Angular + Facebook JS SDK login: Not requesting my

2019-08-29 11:22发布

问题:

FB.login() is not working. The FB Popup is not requesting the right permissions. I can clearly see, in the source code that there's a fn handler that uses the right parameters / parameters being set correctly. I'd like to understand why isn't this working ?

This is the code I've got so far:

http://jsbin.com/IteY/1/

This is where I'm setting the permissions list:

facebook.login(function(response) {
    console.log(response);
}, {scope: 'email,user_likes'});

in accordance with the docs ( https://developers.facebook.com/docs/reference/javascript/FB.login/ )

by doing console.log in the fn handler for login(), I get the fn function(response){ ... } and the {scope: 'email,user_likes'}

I found some other users reporting the same issue using the FB SDK here in SO. I tried the tip to use "perms" instead of "scope", but I get:

OAuth2 specification states that 'perms' should now be called 'scope'. Please update.

  • Not appearing to be the problem. This also shows that the param is being send there. Go wonder why's not working ?! I've cleaned cache too

  • Originally I've reported this issue (AngularJS: DI Error - No module: $facebook, why isn't working?) that was solved. Now having access to the FB object I'm not able to get the right permissions from the user. I'm sure that this is an issue related with Facebook API and not the Angular module

**** I've also tried to check the permissions by using .api like :

facebook.api('/me/permissions', function (response) {
    console.log(response);
} );

console.log reports:

Object {error: Object}

***** Now I've tried to access through the graph using the access_token:

https://graph.facebook.com/me/permissions?access_token=XXXXXXXX

and I can see the right permissions, but the Facebook login popup never asked me about them ? Shouldn't it ?

  {
     "data": [
        {
           "installed": 1,
           "basic_info": 1,
           "email": 1,
           "read_friendlists": 1,
           "user_likes": 1,
           "user_online_presence": 1,
           "user_friends": 1
        }
     ],
     "paging": {
        "next": "xxxxxxx"
     }
  }

I've now asked a different user, who I've added to my sandbox as an admin and he got the required permissions popup! So, I think is something to do, with my own username who had this permissions already set or something - even though I tried to delete the cache, etc!

So, there's no issue to solve. Hope this is useful for someone else in the future!

Any one experienced can take a look ?

Thank you

回答1:

Try attaching a listener to the facebook login event / statuschange:

$facebookProvider.Event.subscribe('auth.authResponseChange', function (response) {
    console.log(response);
})

And look at the response element to see if you have an error or not