我已经阅读了 fb 文档并编写了将消息发布到 facebook“页面”的代码,但是我收到了一个我不希望看到的错误:
(#200) The user hasn't authorized the application to perform this action
这是我所做的:
- 我设置了一个 facebook 应用程序,它提供了我的
APP_ID
和APP_SECRET
. - 我建立了一个测试facebook“页面”。让我们将其 fb id 称为
PAGE_ID
. - 使用 OAuth 为用户获取
USER_ACCESS_TOKEN
范围为“publish_actions,manage_pages”。当重定向到 facebook auth 页面时,我接受了我的应用程序请求的权限。 - 我使用 GET 进行了一次 GET
https://graph.facebook.com/me/accounts
,USER_ACCESS_TOKEN
然后我返回了我管理的页面列表,包括我想要发布到的页面。
我的页面的这个数据块如下所示:
{
"data": [
{
"category": "Community",
"name": "My Generic Test Page",
"access_token": PAGE_ACCESS_TOKEN,
"id": PAGE_ID,
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
},
....
]
}
然后我使用PAGE_ACCESS_TOKEN
向页面发布消息:
- 我做了一个 POST
https://graph.facebook.com/PAGE_ID/feed
的字段message
等于This is a test post.
脸书返回:
{
"error": {
"message": "(#200) The user hasn't authorized the application to perform this action",
"type": "OAuthException",
"code": 200
}
}
使用令牌调试器,我可以确认 myPAGE_ACCESS_TOKEN
是有效的,并且具有范围:manage_pages
和publish_actions
.
我在哪里缺少授权应用程序?我需要额外的范围吗?我是否错过了在 facebook 授权屏幕上单击某些内容?我缺少的应用程序上有设置吗?经过几天的调试,我一定对这个问题视而不见。:-|