从facebook获得分数我有点问题。 我可以使用以下示例发布它们:
FB.api('/me/scores/', 'post', { score: myScore }, function(response) {
console.log(response);
});
然后我尝试从facebook收到分数我得到OAuthException 104: “请求此资源需要访问令牌。”
我使用以下代码来获得分数:
FB.api('/MYAPPID/scores/', 'get', function(response) {
console.log(response);
});
不应该由sdk本身发送access_token吗?
答案 0 :(得分:2)
只需添加: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);
});
});
您可以使用USER_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'));