2013-10-09 24 views
0

我試圖按照指導如何擁有登錄按鈕以及如何登錄到FB的導師。如何在FB登錄時請求權限

的代碼如下 -

<script type="text/javascript"> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: '521597764587246', // App ID 
      status: true, // check login status 
      cookie: true, // enable cookies to allow the server to access the session 
      xfbml: true // parse XFBML 
     }); 

     // Additional initialization code here 

     FB.Event.subscribe('auth.authResponseChange', 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; 

       // TODO: Handle the access token 

       // Do a post to the server to finish the logon 
       // This is a form post since we don't want to use AJAX 
       var form = document.createElement("form"); 
       form.setAttribute("method", 'post'); 
       form.setAttribute("action", '/FacebookLogin.ashx'); 

       var field = document.createElement("input"); 
       field.setAttribute("type", "hidden"); 
       field.setAttribute("name", 'accessToken'); 
       field.setAttribute("value", accessToken); 
       form.appendChild(field); 

       document.body.appendChild(form); 
       form.submit(); 

      } 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. 
      } 
     }); 

    }; 

    // 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)); 
</script> 

我所試圖實現的是對用戶的牆上寫了permmision。

如何在登錄時獲得其他權限?

+0

你根本沒有在Facebook上登錄該代碼。如果您不知道Facebook登錄應用程序的基本原理,請先閱讀官方文檔:https://developers.facebook.com/docs/facebook-login/ – CBroe

回答

0

這裏是一個Facebook身份驗證,它要求'發佈'權限,這是您需要代表Facebook用戶發佈狀態更新。

FB.getLoginStatus(function (response) { 
     if (response.status == "connected") { 
      //User is logged into facebook and has authorized your app proceed with wall post 
     }); 
} else if (response.status == "not_authorized") { 
    //User is logged in to facebook but has not authorized your app 
} else if (response.status == "unknown") { 
    //User is not logged in to facebook 
} 
}); 

//This example uses jQuery and a button with id="#fb-login-button", just put the contained code below in whatever click handler your using for your facebook login button 
$("#fb-login-button").click(function() { 
    FB.login($.proxy(function (response) { 
     if (response.authResponse) { 
      //User has autorized proceed with wall post 
     } else { 
      //User did not autorize 
     } 
    }, this), { 
     //Scope is where you specify permissions 
     scope: 'publish_stream' 
    }); 
}); 
相關問題