如果用户未授予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'});
}
当它被称为一个小窗口弹出询问....想要访问您的公开个人资料和朋友列表。有2个按钮好然后取消。当按下Okay时,它会转到另一个屏幕,询问....想要代表您发布给您的朋友。再次2按钮,Okay和Skip。
当我按第一个跳过拒绝所有权限时,它不会返回任何内容。警报(“命中”);不叫。
当我在第一次提示时按Ok,然后进入第二个弹出窗口并代表发布询问。我按下Okay,调出警告'Granted'。
当我按下跳过时,即使我点击跳过,也会调用警告'Granted'。
答案 0 :(得分:3)
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
答案 1 :(得分:1)
也许这种情况正在发生,因为您试图在弹出窗口中打开Facebook登录,但它会在您调用fb.login的同一窗口中打开。当您单击取消时,Facebook会尝试关闭窗口,但由于它未被Facebook打开,窗口将不会关闭。它永远不会尝试跟随回调网址。
尝试使用config {display:“touch”}或{display:“page”},如下所示:
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', display: 'page'});
}
答案 2 :(得分:0)
有没有理由不在一个屏幕上要求所有需要的权限。但是,请记住,根据facebook文档,请求几个权限开始,然后继续增加权限请求。
https://developers.facebook.com/docs/reference/login/#permissions
试试此代码
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log('Access Token = '+ access_token);
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: ''});
希望有所帮助