如果用户未授予publish_stream权限,我会尝试获取用户权限。
我有这个功能:
function AskPermission()
{
ResizeUnity(0);
FB.login(function(response)
{
alert("Hit");
if (response.authResponse)
{
alert('Granted!');
GetUnity().SendMessage("POST", "POST", "Granted");
}
else
{
alert('User cancelled login or did not fully authorize.');
GetUnity().SendMessage("POST", "POST", "");
}
ResizeUnity(1);
}, {scope: 'publish_stream'});
}
当它被调用时,会弹出一个小窗口,询问....想要访问您的公开个人资料和 friend 列表。有 2 个按钮“确定”和“取消”。当按下“确定”时,它会转到另一个屏幕,询问....愿意代表您向您的 friend 发帖。再次按 2 个按钮,确定并跳过。
当我按下第一个跳过拒绝所有权限时,它不会返回任何内容。警报(“命中”);不被调用。
当我在第一个提示上按“确定”时,它会转到第二个弹出窗口并询问代表发布的信息。我按确定,警报“已授予”被调用。
当我按下“跳过”时,即使我按下“跳过”,也会调用警报“Granted”。
最佳答案
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized'){
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
使用此 Facebook 功能来检查用户是否授予权限。
如果用户不允许您的应用程序,您可以调用相同的功能。如需更多代码帮助,我可以帮助您。 :)
有关更多信息,请参阅:Fb.getLoginStatus
关于javascript - 如果选择取消,FB.login 不会调用回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15822190/