Facebook OpenGraph:提交新动作

Pau*_*nne 3 facebook-graph-api

我刚刚开始使用Facebook SSO和OpenGraph.我有SSO使用我的iOS应用程序,现在我开始看到如何发布OpenGraph操作.

我已经设置了一个新的动作类型,我需要提交它.当我这样做时,我收到错误:

您必须使用此操作类型向时间轴发布至少一个操作.查看文档.

好的,所以我点击了有用的文档链接,它告诉我我想这样做:

https://graph.facebook.com/me/recipebox:cook?recipe=http://www.example.com/pumpkinpie.html&access_token=YOUR_ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)

所以我将其翻译成:

https://graph.facebook.com/me/fotoferret:hug?ferret=http://www.example.com/pumpkinpie.html&access_token=MY_ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)

fotoferret是我的命名空间,拥抱是我的行动

其中MY_ACCESS_TOKEN是返回的值:

https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=MY_APP_ID&client_secret=MY_APP_SECRET
Run Code Online (Sandbox Code Playgroud)

当我粘贴我翻译的URL时,我收到此错误:

{
   "error": {
      "message": "An active access token must be used to query information about the current user.",
      "type": "OAuthException",
      "code": 2500
   }
}
Run Code Online (Sandbox Code Playgroud)

这一点我很困惑.我已经尝试将动作发布到我的时间轴,但它告诉我我需要一个活动的访问令牌,我已经提供了.那么我该如何发布一个动作呢?

phw*_*hwd 6

使用应用访问令牌时,请使用用户的ID /me.您正在代表应用程序执行操作,而不是直接对用户执行操作.

用户访问令牌

https://graph.facebook.com/me/fotoferret:hug?ferret=http://www.example.com/pumpkinpie.html&access_token=MY_ACCESS_TOKEN

应用访问令牌

https://graph.facebook.com/ID/fotoferret:hug?ferret=http://www.example.com/pumpkinpie.html&access_token=MY_ACCESS_TOKEN

使用Graph Explorer时,请确保将选项切换到POST而不是获取GET.GET默认情况下设置,因此它将返回不创建操作的操作.

或者使用cURL

curl -F 'access_token=MY_ACCESS_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/ID/fotoferret:hug
Run Code Online (Sandbox Code Playgroud)

如果您启用了"需要应用程序令牌发布"并获取

{"error":{"message":"(#15) This method must be called with an app access_token.","type":"OAuthException","code":15}}

这意味着你正在使用

curl -F 'access_token=MY_ACCESS_USER_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/me/fotoferret:hug
Run Code Online (Sandbox Code Playgroud)

使用MY_APP_TOKEN.如果你得到,

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

这意味着你正在使用

curl -F 'access_token=MY_APP_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/me/fotoferret:hug
Run Code Online (Sandbox Code Playgroud)

您应该使用数字ID

curl -F 'access_token=MY_APP_TOKEN' \
-F 'ferret=http://www.example.com/pumpkinpie.html' \
https://graph.facebook.com/ID/fotoferret:hug
Run Code Online (Sandbox Code Playgroud)

如果你得到

{"error":{"message":"(#200) Requires extended permission: publish_actions","type":"OAuthException","code":200}}

用户在其设置中没有针对我/权限的publish_actions操作,它应该在那里,"publish_actions": 1如果不是,通过选择"获取访问令牌"并选择(您必须更改为适合您的应用程序代码范围)来授予权限好)