本文介绍了Facebook Javascript SDK 开放图:为自定义故事添加自定义对象时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为Opinion"的自定义对象来围绕它构建自定义故事.

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

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

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

facebook 给我的示例代码是:

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

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

The reponse is an error (OAuth Exception):

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

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

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

(#100) The parameter object is required

如果我从路径中删除 [namespace]:opinion 也是一样.

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?

推荐答案

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

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.

比如,

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 给出的 curl 示例/using-object-api/

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/

这篇关于Facebook Javascript SDK 开放图:为自定义故事添加自定义对象时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 14:12