[英]FB.login not calling callback if cancel is selected
如果用戶未授予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個按鈕,確定並取消。 按下“確定”后,它會轉到另一個屏幕,詢問..代表您發給您的朋友。 再按2個按鈕,確定並跳過。
當我按下第一個跳過按鈕拒絕所有權限時,它不會返回任何內容。 警報(“命中”); 不被調用。
當我在第一個提示上按“確定”時,它會轉到第二個彈出窗口,並代表您詢問有關發布的信息。 我按“確定”,將調用警報“已授予”。
當我按跳過鍵時,即使我單擊跳過鍵,也會發出“已授予”警報。
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
可能是因為您正在嘗試在彈出窗口中打開Facebook登錄名,但它會在您調用fb.login的同一窗口中打開。 當您單擊“取消”時,Facebook嘗試關閉窗口,但由於Facebook沒有打開它,因此該窗口不會關閉。 它從不嘗試遵循回調URL。
嘗試像這樣在配置{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'});
}
是否有一個原因,為什么不在一個屏幕本身中要求所有權限。 但是,請記住,按照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: ''});
希望能有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.