2013-03-21 87 views
0
"<div id='fb-root'></div> 
<script> 
    window.fbAsyncInit = function() 
    { 
     FB.init({ 
      appId: 'ID', 
      status: true, 
      cookie: true, 
      xfbml: true 
     }); 

     FB.getLoginStatus(function(response) 
     { 
       if(response.status === 'connected') 
       { 
        if (response.authResponse != 'undefined') 
        { 
         window.location = '/fb_redirect.php'; 
        } 
       } else if(response.status === 'not_authorized') 
       { 

       } else 
       { 
        FB.Event.subscribe('auth.login', function(response) 
        { 
         window.location = '/fb_redirect.php'; 
        }); 
       } 
      }); 
     }; 

     (function(d, s, id) { 
      var js, fjs = d.getElementsByTagName(s)[0]; 
      if (d.getElementById(id)) return; 
      js = d.createElement(s); js.id = id; 
      js.src = '//connect.facebook.net/en_US/all.js#xfbml=1&appId=ID'; 
      fjs.parentNode.insertBefore(js, fjs); 
      }(document, 'script', 'facebook-jssdk')); 
    </script> 

<div class='fb-login-button' data-show-faces='false' scope='email' registration-url='http://www.sportannica.com/fb_redirect.php' size='large' data-width='200' data-max-rows='1'></div> 

這就是我現在使用的。對於已經接受該應用的用戶來說,它可以正常工作。但是,對於第一次使用的用戶,點擊登錄按鈕後,就不會彈出任何屏幕,並顯示有關應用程序的詳細信息,例如有多少人使用它或者請求的是哪種類型的權限。它只是前往/fb_redirect.php。FB登錄按鈕不提示第一次用戶的範圍

enter image description here

看到在知情同意指定網站的網址?是登錄到FB並接受應用程序後頁面被重定向到的URL嗎?

回答

0

當用戶未在Facebook上登錄時,使用登錄按鈕,如果用戶已登錄但未授予您應用的權限,則應使用oauth對話框。

你可以這樣做

FB.getLoginStatus(function(response) { 
    if(response.status === 'connected'){ 
     if (response.authResponse != 'undefined') 
      window.location = '/fb_redirect.php'; 
    }else if(response.status === 'not_authorized'){ 
    //it means we have a user but he hasn't granted any permissions to our app 
    //we're going to redirect him to the permission page 
    window.location = 'https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&response_type=code&redirect_uri=YOUR_APP_URL&scope=email'; 
    } else { 
    //the user is not logged in, as you already have a login button you don't have to do nothing 
    } 
}); 

//this should be outside the FB.getLoginStatus function 
FB.Event.subscribe('auth.login', function(response) { 
    window.location = '/fb_redirect.php'; 
}); 
+0

謝謝。但是,在fb_redirect文件中......會話已啓動,或者如果它是首次執行插入查詢的用戶。這些都需要在登錄按鈕所在的頁面上發生嗎? – Lance 2013-03-22 22:12:34

+0

你能解釋一下自己嗎? – 2013-03-22 22:17:59

+0

我現在連接到的互聯網不會讓我通過ftp連接到我的遠程服務器。所以,我無法上傳你的代碼,看看它是否有效。但是,從以前的經驗來看,window.location ='some_other_file.php'從來沒有用過。出於某種原因,儘管window.reload()似乎工作得很好。 – Lance 2013-03-22 22:22:30

0

正確的語法實現這一點是data-scope="email",不scope="email"