以下是我迄今为止的Facebook API JavaScript代码。它非常简单,有一堆
目前,
引用:
console.log()
来跟踪代码流程。(我知道将参数命名为response和response2是可怕的做法,但这只是为了避免命名冲突而快速输入的。)目前,
FB.init()
成功,FB.getLoginStatus()
也起作用,并且两个FB.api()
调用也正常运行,但是FB.login()
从未发生过。虽然它是异步的,但console.log()
在之前和之后确实执行了。总之,我的控制台输出是:引用:
makes it here
makes it here too
Permissions:
Object {data: Array[37]}
Good to see you, my-name-is-here.
FB.login()
调用从未收到响应,因此回调从未触发,因此函数内部没有console.log()
。但我需要这个FB.login()
才能获取扩展权限ads_management
。您有什么想法,或者至少可以指导我解决这个问题的方向吗?window.fbAsyncInit = function() {
FB.init({
appId: 'my-app-id-is-here',
xfbml: true,
version: 'v2.0'
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me', function(response2) {
console.log("Good to see you, " + response2.name + ".");
});
FB.api('/me/permissions', function(response2) {
console.log("Permissions:");
console.log(response2);
});
console.log("makes it here");
FB.login(function(response2) {
console.log("why not here?");
if (response2.authResponse) {
console.log("Response to login asking for ads_management permission");
console.log(response2);
} else {
console.log("User cancelled login or did not fully authorize.");
}
}, {
scope: 'ads_management',
return_scopes: true
});
console.log("makes it here too");
} else {
// filled with other code that doesn't effect this question yet
}
});
};
更新:
移除参数 {scope: 'ads_management', return_scopes: true}
后,调用 FB.login()
至少会尝试运行,但控制台中出现以下错误:
"FB.login() called when user is already connected."
但我原本认为在用户已经登录的情况下获取更多权限的方法是通过再次调用 FB.login()
,并在参数中指定所需的权限。