我正在尝试使用 javascript sdk 发布到已连接用户的 Facebook 墙,这是我的代码:
var connecter=false;
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxx', // App ID
oauth : true,
channelUrl : '//www.streamazing.net/js/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.login', function (response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function (response) {
window.location.reload();
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
connecter=true;
FB.api('/me', function(user) {
var user2=user;
console.log(user2.name);
});
}
else connecter=false;
});
var body = 'This is a test';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
console.log(response.error);
} else {
alert('Post ID: ' + response.id);
}
});
};
这是控制台日志:
code: 2500
message: "An active access token must be used to query information about the current user."
type: "OAuthException"
我用此代码请求许可:
<fb:login-button autologoutlink='true' scope='email,user_birthday,status_update,publish_stream'></fb:login-button>
我不明白为什么 Facebook 要求我提供访问令牌,有人可以帮助我吗? 非常感谢。
如果您想使用 Javascript SDK 发布到用户的源,请改用 FB.ui。 http://developers.facebook.com/docs/reference/javascript/FB.ui/
否则,publish_stream扩展权限所需的访问令牌存储在response.authResponse.accessToken下的FB.getLoginStatus方法中。 http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
您需要使用access_token=向所有FB URL发出请求。
调用 FB.init();在声明了所有 fb sdk 函数之后。