Posting a Custom Story to Facebook Open Graph

核能气质少年 提交于 2019-12-08 13:12:50

问题


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.

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

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);

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

"[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."

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?


回答1:


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/

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



来源:https://stackoverflow.com/questions/18341888/posting-a-custom-story-to-facebook-open-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!