12

我创建了一个名为“意见”的自定义对象来围绕它构建自定义故事。

我正在尝试使用 javascript sdk 从我的网站添加一些应用程序拥有的对象。

facebook给我的示例代码是:

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

响应是一个错误(OAuth 异常):

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

如果我删除type参数,我会得到另一个错误:

(#100) The parameter object is required

如果我[namespace]:opinion从路径中删除,则相同。

我不明白为什么,谷歌搜索后没有关于此的参考。

为什么这个?我可以参考任何资源来解决这个问题吗?

4

2 回答 2

19

该对象是对象的 JSON 编码版本,为您生成的示例代码不正确。还要从参数列表中删除类型。

所以像,

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

它的外观示例可以在http://philippeharewood.com/facebook/objectify.html中看到,它基于https://developers.facebook.com/docs/opengraph/using-object给出的 curl 示例-api/

于 2013-06-22T22:49:44.153 回答
3

对于在 iOS 上遇到类似问题的任何人,示例代码似乎又是错误的,但以下似乎有效:

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 {
        ...
    }
}];
于 2014-01-26T18:15:57.960 回答