3

我正在使用fb js sdk在omniauth-facebook上工作。它現在工作很好,但我不知道爲什麼它不能請求額外的權限。我已經在omniauth.rb中設置了:omniauth-facebook的作用域,但是當我單擊登錄時,我沒有得到任何我想要從用戶請求的額外權限。我尋求在互聯網上發現,我所要做的,如:facebook javascript sdk使用omniauth-facebook獲得額外的權限

FB.login(function(response) { 
// handle the response 
}, {scope: 'email,user_likes'}); 

但在我而言,我按照客戶端,並與該出來:

(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  : 'app_id', // App ID 
     channelUrl : '//'+window.location.hostname+'/channel', // Path to your Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
    oauth  :true, //enable Oauth 2.0 
     xfbml  : true // parse XFBML 
    }); 

    // listen for and handle auth.statusChange events 
// 
FB.Event.subscribe('auth.login', function(response) { 
    if (response.authResponse) { 
    window.location = '/auth/facebook/callback'; 
    } 
}, {scope: 'email,user_likes'}); //i tried but its not working 

    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){ 
      if (me.name) { 
      document.getElementById('auth-displayname').innerHTML = me.name; 
      } 
     }) 
     document.getElementById('auth-loggedout').style.display = 'none'; 
     document.getElementById('auth-loggedin').style.display = 'block'; 
     } else { 
     // user has not auth'd your app, or is not logged into Facebook 
     document.getElementById('auth-loggedout').style.display = 'block'; 
     document.getElementById('auth-loggedin').style.display = 'none'; 
     } 
    }); 

    // respond to clicks on the login and logout links 
    document.getElementById('auth-loginlink').addEventListener('click', function(){ 
     FB.login(); 
    }); 


    document.getElementById('auth-logoutlink').addEventListener('click', function(){ 
     FB.logout(); 
    }); 
    } 

如果我使用Facebook社交按鈕並在html中添加範圍,它可以工作,但這不是我想要的。這裏的任何人都得到了教程或提示我繼續?

回答

0

這個怎麼樣:

jQuery -> 
    $('body').prepend('<div id="fb-root"></div>') 

    $.ajax 
    url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js" 
    dataType: 'script' 
    cache: true 


window.fbAsyncInit = -> 
    FB.init(appId: '<%= ENV["FACEBOOK_KEY"] %>', cookie: true) 

    $('#sign_in').click (e) -> 
    e.preventDefault() 
    FB.login (response) -> 
     window.location = '/auth/facebook/callback' if response.authResponse 
    , scope: "email, publish_stream"  

    $('#sign_out').click (e) -> 
    FB.getLoginStatus (response) -> 
     FB.logout() if response.authResponse 
    true