我正在尝试编写一个小FB应用程序。我的代码如下。
$(function() {
$.ajaxSetup({cache: true});
$.getScript('//connect.facebook.net/en_UK/all.js', function() {
loadAPI();
});
});
function loadAPI() {
// init the FB JS SDK
FB.init({
'appId': '...',
'channelUrl': '...',
'status': true,
'cookie': true,
'xfbml': true
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me', 'get', {fields: 'permissions'}, function(response) {
perms = response.permissions;
if (!perms || !perms.data || !perms.data[0]) {
//error
} else if (perms.data[0]['email'] == 1) {
alert('Perms given!');
} else {
initBtn();
}
});
} else if (response.status === 'not_authorized') {
initBtn();
} else {
// the user isn't logged in to Facebook.
FB.login();
}
});
}
function initBtn() {
$('#btn').click(function() {
FB.ui({method: 'permissions.request', scope: 'email'}, function(response) {
if (response) {
FB.api('/me', 'get', {fields: 'email, name'}, callbackFn);
} else {
...
}
});
});
}
function callbackFn(response) {
if (response) {
...
}
}
在我致电callbackFn
之前,一切正常。在这个函数中我想使用用户数据。该函数的响应是:
error: Object
code: 2500
message: "An active access token must be used to query information about the current user."
type: "OAuthException"
知道我可能做错了吗?