Facebook Javascript SDK open-graph: error adding custom objects for custom stories

青春壹個敷衍的年華 提交于 2019-11-29 07:47:20

问题


I've created a custom object, called 'Opinion' to build custom stories around it.

I'm trying to add some app-owned objects from my website using the javascript sdk.

The sample code facebook gives me is:

FB.api(
  'me/objects/[namespace]:opinion',
  'post',
  {
    app_id: xxxxxxxx,
    type: "[namespace]:opinion",
    url: "http://samples.ogp.me/331257847005141",
    title: "Sample Opinion",
    image: "https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png",
    description: ""
  },
  function(response) {
    // handle the response
  }
);

The reponse is an error (OAuth Exception):

2500: Cannot specify type in both the path and query parameter.

If i remove the type parameter, i get another error:

(#100) The parameter object is required

Same if I remove [namespace]:opinion from the path.

I don't understand why, and there's no reference about this after googling it.

Why this? Any resource i can refer to solve that?


回答1:


The object is a JSON-encoded version of an object, the sample code generated for you was incorrect. Also remove type from the parameter list.

So something like,

FB.api(
  'me/objects/[namespace]:opinion',
  'post',
  {
    object: {"app_id":xxx,"url":"http:\/\/samples.ogp.me\/331257847005141","title":"\"Sample Opinion\"","image":"https:\/\/s-static.ak.fbcdn.net\/images\/devsite\/attachment_blank.png","description":"\"\""}
  },
  function(response) {
    // handle the response
  }
);

An example of how it looks can be seen at http://philippeharewood.com/facebook/objectify.html and it was based off the curl example given at https://developers.facebook.com/docs/opengraph/using-object-api/




回答2:


For anyone struggling with a similar problem on iOS, the sample code again appears to be wrong, however the following seems to work:

NSMutableDictionary<FBOpenGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:@"<appnamespace>:<objecttype>"
    title:@"..."
    image:[result objectForKey:@"uri"]
      url:nil
  description:@"..."];

[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
    // handle the result
    if ( error ) {
        DLog(@"error %@ creating object", error);
    } else {
        ...
    }
}];


来源:https://stackoverflow.com/questions/17153617/facebook-javascript-sdk-open-graph-error-adding-custom-objects-for-custom-stori

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