使用JavaScript SDK不接受访问令牌的图形API
问题描述:
对于这个问题,我一直在绞尽脑汁,加载JavaScript SDK后,我无法对图形API进行任何GET调用。我试图使用/我/家,但我也尝试/我以及用于调试目的。奇怪的是,如果我检查用户的登录状态,它会返回一个访问令牌,我可以使用它来在地址栏中完美地检索新闻馈送。但是,只要我使用JavaScript对Graph API进行GET调用,就会得到:使用JavaScript SDK不接受访问令牌的图形API
“必须使用活动访问令牌来查询有关当前用户的信息。
此外,我可以使用SDK的用户的饲料使POST调用完美罚款。最后,我已经检查确保我具有read_stream权限。
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo($facebook_key); ?>', // App ID
channelUrl : '//'+window.location.hostname+'/channel.php', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
console.log(response);
} else {
location.href='welcome.php';
};
});
FB.getLoginStatus(function(response) {
console.log(response);
});
//get Facebook news feed
FB.api('/me/home', 'get', function(response) {
console.log(response);
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
//status update function
function post (form) {
var status = form.status.value;
FB.api('/me/feed', 'post', { message: status }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Status updated');
};
});
};
答
我会尝试你的电话移到/我进入你的FB.getLoginStatus功能:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
//get Facebook news feed
FB.api('/me/home', 'get', function(response) {
console.log(response);
});
}
});
我认为这个问题是,确认了身份验证之前,你的API调用被解雇。希望将此函数移入getLoginStatus回调应该可以解决此问题。
你可以在这里看到更多的例子https://developers.facebook.com/tools/console/
哇,谢谢!我不能为我的生活找出什么是错的。 – Jimbroze 2012-07-27 17:03:45