How to request permissions for facebook application using JavaScript

How to check the current user login status and request permissions for my application? This has recently changed, and now my application no longer works. Thank you for your help!

+4
source share
3 answers

I always use this setting to handle login status and permissions:

function getPerms() { FB.login(function(response) { if (response.authResponse) { //user has granted permissions } }, {scope:"email, ..."}); } function getStatus() { FB.getLoginStatus(function(response) { if (response.status === "connected") { //user has granted permissions } else { getPerms(); } }); } 

You still need to enable all.js and call FB.init(...)

+4
source

Here's how you can do it:

  FB.init( { "appId" : xxxxxxxxxx, "status" : true, "cookie" : true, "xfbml" : true, "oauth" : true }); FB.Event.subscribe('auth.authResponseChange', function(response) { // need to wait few seconds for fb login status to work in FireFox setTimeout('window.location.reload()', 3000); }); function fbConnect(){ FB.getLoginStatus(function(response) { if (response.authResponse){ FB.login(function(response) { if (response.authResponse) { } else { //console.log('User cancelled login or did not fully authorize.'); } }, {"scope":"email,manage_pages"}); } }); } 

You need to call the fbConnect() function.

Also make sure you have the <body> on your page:

 <div id="fb-root"></div> <script src="//connect.facebook.net/en_US/all.js"></script> 
0
source
  • You need to provide code to get more accurate answers.
  • Most likely you have not updated your code to use OAuth 2.0, see here
  • From the link above, use scope instead of perms
  • Use response.authResponse instead of response.session
  • Welcome to Stackoverflow!
0
source

Source: https://habr.com/ru/post/1392058/


All Articles