只需添加:FB.setAccessToken({USER_TOKEN});
例子 :
FB.setAccessToken({USER_TOKEN});
FB.api('/me/scores/', 'post', { score: 1000 }, function(response) {
console.log(response);
FB.api('/{APP_ID}/scores/', 'get', function(response2) {
console.log(response2);
});
});
您可以通过以下方式获取 userAccessTokenUSER_TOKEN = FB.getAuthResponse()['accessToken'];
完整示例:
window.fbAsyncInit = function() {
FB.init({
appId : '{YOUR_APP_ID}',
cookie : true,
xfbml : true,
version : 'v2.3'
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var access_token = FB.getAuthResponse()['accessToken'];
FB.setAccessToken(access_token);
FB.api('/me/scores/', 'post', { score: 1000 }, function(response) {
console.log(response);
FB.api('/{APP_ID}/scores/', 'get', function(response2) {
console.log(response2);
});
});
}
});
}
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));