javascript - facebook javascript sdk 使用 omniauth-facebook 获得额外权限

标签 javascript facebook permissions facebook-javascript-sdk omniauth

我正在使用 fb js sdk 开发 omniauth-facebook。它现在工作得很好,但我不知道为什么它不能请求额外的权限。我已经在我的 omniauth.rb :scope 中设置了 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 中添加范围,它可以工作,但这不是我想要的。这里有人有教程或提示让我继续吗?

最佳答案

这个怎么样:

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

关于javascript - facebook javascript sdk 使用 omniauth-facebook 获得额外权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10733447/

相关文章:

javascript - body 背景改变?

javascript - 如何将图像从桌面拖放到编辑器中并移动它?

c# - 在 SharePoint 中使用 BreakRoleInheritance() 时 true 和 false 之间的区别

php - 拒绝访问 - 使用预签名 URL 的 S3 资源 - PHP SDK

Javascript onkeypress 删除或点

javascript - 有什么方法可以在调用构造函数之前重新设置 Function 对象的 "this"引用吗?

facebook - 这是什么? (Facebook Offline Conversions API)错误#21009 - 数据集上传暂时未准备好

facebook - 我无权使用 javascript 在 Facebook API 上获取所有 invitable_friends

ios facebook 喜欢 objective-c 中的 react

java - 权限不是可更改的权限类型