Using firebase facebook auth with facebook graph api

前端 未结 1 327
暖寄归人
暖寄归人 2021-01-07 08:14

I am using firebase facebook simple login.

Is there any way I can use it conjunction with facebook js graph api?

Let say, calling FB.api(\'xxx\', funct

1条回答
  •  囚心锁ツ
    2021-01-07 09:04

    Facebook via Firebase Simple Login returns the Facebook access token as part of the payload. You could then use this directly with the Facebook Graph API and their JavaScript SDK:

    var ref = new Firebase(URL);
    var auth = new FirebaseSimpleLogin(ref, function(error, user) {
      if (user) {
        var facebookToken = user.accessToken; // <<-- here it is
      }
    });
    
    // Note: Attach this to a click event to permit the pop-up to be shown
    auth.login('facebook');
    

    As you noted, Singly is another great approach that abstracts some of the effort of talking to Facebook, but shouldn't be necessary if your use case is fairly straightforward.

    UPDATE

    Firebase Simple Login now supports authenticating a user with an existing Facebook access token, meaning that you can easily use the Facebook JS SDK in combination with Firebase Simple Login without asking your users to authenticate twice.

    For example, once you have a valid Facebook access token using the Facebook JS SDK:

    var ref = new Firebase(...);
    var auth = new FirebaseSimpleLogin(ref, function(error, user) { ... });
    auth.login('facebook', { access_token: '' });
    

    See the access_token option at https://www.firebase.com/docs/security/simple-login-facebook.html for more information.

    0 讨论(0)
提交回复
热议问题