Facebook Open Graph API 调用出现问题...需要主动访问令牌吗?
我在我的网站上使用 Facebook 的开放图 api 以及 JavaScript SDK。我的目标是让用户连接到我的网站,然后在我的网站上执行某些操作后向用户 Facebook 流发布一条消息。我的 Facebook 连接功能运行良好。在连接过程中,我请求电子邮件、publish_stream、offline_access 权限。我想这些就是我想做的事情所需要的全部。现在,当用户通过 facebook connect 连接时,我确实获取并捕获了 facebook 访问令牌和秘密,尽管我不知道如何处理它们。
根据 Facebook 的 JavaScript SDK 伪劣文档...要做我想做的事情,它说使用以下代码:
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
我只是将其作为测试,而不是警告响应,而是对 JSON 进行字符串化响应并写入控制台。可以说流发布失败并且响应是这样的:
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
如果用户通过 facebook connect “连接”到我的网站并接受我指定的所有权限,那么我没有有效的访问令牌吗?访问令牌是我必须传递给 api 调用的另一个参数吗?
I'm using Facebook's open graph api along with the JavaScript SDK on my site. My goal is for a user to connect to my site and then after performing certain actions on my site publish a message to the users facebook stream. I have the facebook connect function working just fine. During the connect I request email, publish_stream, offline_access permissions. I think those are all I need for what I'm trying to do. Now when the user connects via facebook connect I do get and capture the facebook access token and secret though I don't know what to do with them.
According to Facebook's shoddy documentation for the JavaScript SDK... to do what I'm trying to do it says to use the following code:
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
I'm doing just that as a test and instead of alerting the response I'm stringifying the JSON response and writing to the console. Suffice it to say the stream publish fails and the response is this:
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
If the user is 'connected' to my site via facebook connect and accepted all the permissions I specified, don't I have a valid access token? Is the access token another parameter I have to pass to the api call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保页面中包含所有这些内容:
Make sure you have all this in the page:
上面的代码对我来说适用于publish_stream权限。确保在 javascript api 收到访问令牌之前代码未运行。 直接在 FB.api 调用上方运行:
以确保您拥有 access_token。
The above code worked for me with the publish_stream permission. Make sure that the code is not running before the javascript api has received the access token. Run:
directly above the FB.api call to make sure you have an access_token.