将 firebase facebook auth 与 facebook graph api 一起使用 [英] Using firebase facebook auth with facebook graph api

查看:21
本文介绍了将 firebase facebook auth 与 facebook graph api 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 firebase facebook 简单登录.

I am using firebase facebook simple login.

有什么方法可以将它与 facebook js graph api 结合使用吗?

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

比方说,调用 FB.api('xxx', function(){}) ?

推荐答案

Facebook 通过 Firebase 简单登录返回 Facebook 访问令牌作为有效负载的一部分.然后,您可以直接将其与 Facebook Graph API 及其 JavaScript SDK 一起使用::>

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');

正如您所指出的,Singly 是另一种很好的方法,它抽象了与 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.

更新

Firebase 简单登录现在支持使用现有 Facebook 访问令牌对用户进行身份验证,这意味着您可以轻松地将 Facebook JS SDK 与 Firebase 简单登录结合使用,而无需要求用户进行两次身份验证.

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.

例如,一旦您拥有使用 Facebook JS SDK 的有效 Facebook 访问令牌:

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: '<ACCESS_TOKEN>' });

请参阅 https 上的 access_token 选项://www.firebase.com/docs/security/simple-login-facebook.html 了解更多信息.

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

这篇关于将 firebase facebook auth 与 facebook graph api 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆