将自定义故事发布到Facebook打开图 [英] Posting a Custom Story to Facebook Open Graph

查看:58
本文介绍了将自定义故事发布到Facebook打开图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义故事发布到概念验证Facebook应用程序中,该应用程序由对象类型徽章"和动作类型赚钱"组成.当我在Facebook Open Graph Types界面中为此获取代码"时,Graph Explorer示例成功地将故事发布到了我的时间轴上.但是,一个参数(徽章")是对OG样本的URL引用.

I'm trying to post a custom story to a proof of concept Facebook app, consisting of an object type "badge" and an action type "earn." When I "get code" for this in the Facebook Open Graph Types interface, the Graph Explorer example successfully posts the story to my timeline. However, the one parameter ("badge") is a URL reference to OG samples.

如何直接发布一些内容,而不作为OG示例的参考?

How can I post something directly, not as a reference to OG samples?

使用C#SDK,我目前正在尝试这样做:

Using the C# SDK, I'm currently trying this:

var client = new FacebookClient();
client.AccessToken = tokenResult.access_token;

dynamic parameters = new ExpandoObject();
parameters.badge = @"
    {
        ""app_id"" : [my app ID],
        ""title"" : ""Widget Badge"",
        ""image"" : ""[a public image URL]"",
        ""url"" : ""[a public website URL]"",
        ""type"" : ""[my custom namespace]:badge""
    }
    ";

var result = client.Post("/me/[my custom namespace]:earn", parameters);

但是,我从Facebook回来的例外是:

However, the exception I'm getting back from Facebook is:

"[上述JSON]"是类型为参考"的属性徽章"的无效值

"[the above JSON]" is an invalid value for property "badge" with type "Reference"

在网上找到一些代码片段后,我尝试将上面的属性徽章"更改为通用的帖子"(我想依靠类型"值可以知道它的内容),但是随后出现错误说我缺少必需的参数徽章".

Following some code snippets I've found online, I tried changing the property "badge" above to a generic "post" (I would guess relying on the "type" value to know what it's posting), but then the error says that I'm missing the required parameter "badge."

在这种情况下,我什么都没有告诉我什么是引用"类型,尽管我可能会忽略一些东西.在原始示例中,它是OG示例的URL,但是我认为我们可以发布自定义内容,而不仅仅是示例.我是否需要使用OG Samples之类的meta标签中的值托管自己的某种样本"页面,还是可以直接在帖子中以某种方式直接指定值?

I haven't found anything which tells me what a "Reference" type is in this case, though I could just be overlooking something. In the original example it was a URL to OG Samples, but I would assume we can post custom things and not just samples. Do I need to host some sort of "sample" page of my own with the values in meta tags like OG Samples, or can I just specify the values directly in the post somehow?

推荐答案

要发布带有对象的操作,您需要提供该对象的url. 但是,如果您自己的应用程序上没有此URL(您的应用程序没有每个对象的网页),则可以创建直接由Facebook托管的对象,并且该URL将使用此URL的生成ID目的. 为此,您需要使用Object API: https://developers. facebook.com/docs/opengraph/using-object-api/

To post actions with an object, you need to provide the url of this object. But in the case where you don't have this url on your own app (you app doesn't have a webpage for each object), then you can create objects hosted directly by facebook, and the url will use the generated id of this object. To do that, you need to use the Object API : https://developers.facebook.com/docs/opengraph/using-object-api/

提供json数据,它将在facebook opengraph中创建对象,返回其ID(因此您具有url),然后就可以发布操作

Providing the json data, it will create the object in facebook opengraph, returning its id (so you have the url) and then you'll be able to post your action

这篇关于将自定义故事发布到Facebook打开图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆