2012-06-02 32 views
1

我認爲這是一個非常明顯的問題,但我完全難住。我想我已經正確設置了我的應用程序設置,但是當我嘗試在我的網站上驗證(使用JavaScript SDK)我的帳戶,然後使用console.log(我)時,我仍然只獲取公共信息。如何請求用戶信息的權限?

編輯:我認爲我的問題是我的網站使用「當前對話框」,而不是「推薦對話框」。據我所知,只有當有人通過Facebook訪問我的網站時纔會使用推介對話框,但我知道必須有一種方法可以使用我網站上的推薦對話。爲什麼有人甚至會使用當前對話框,如果它只能通過用戶的公共信息驗證服務器?我讀過另一篇文章,說我應該查看身份驗證文檔(https://developers.facebook.com/docs/authentication/),但據我所知,在推薦對話框授權方面沒有任何內容。

我想使用Javascript SDK。這是可能的,還是我將不得不做,而不使用Javascript SDK?

在身份驗證對話框,我有這樣的:電子郵件,user_about_me,user_likes,USER_LOCATION,user_website,user_checkins

這裏是我的代碼:

// Load the SDK Asynchronously 
    (function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 

    // Init the SDK upon load 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '464723870207650', // App ID 
     channelUrl : '//'+window.location.hostname+'/scripts/channel.php', // Path to your Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 

    // listen for and handle auth.statusChange events 
    FB.Event.subscribe('auth.statusChange', function(response) { 
     if (response.authResponse) { 
     // user has auth'd your app and is logged into Facebook 
     FB.api('/me', function(me){ 
      console.log(me); 
     }) 
     } else { 
     // user has not auth'd your app, or is not logged into Facebook 
     } 
    }); 
    } 

當我通過調試運行它,我不沒有任何錯誤。

回答

2

只要打電話給FB.login方法與所需的權限一起:

function login() { 
    FB.login(function(response) { 
     console.log("FB.login callback, response: ", response); 
    }, { scope: "email,publish_stream,etc" }); 
} 

只需記住:

調用的JS SDK的FB.login結果試圖打開一個彈出窗口 。因此,只有在用戶點擊 事件後才能調用此方法,否則彈出窗口將被大多數瀏覽器阻止。