使用firebase认证令牌使用JS SDK进行图形API调用 [英] Using firebase auth token to make graph api calls using JS SDK
问题描述
我目前有一个使用firebase编写的应用程序来验证并登录到我的应用程序。我得到一个访问令牌与firebase认证。我想使用这个令牌进行图形API调用,如
I currently have a Facebook app written with app that uses firebase to authenticate and login to my app. I am getting a access token with the firebase auth. I wanted to use this token to make graph api calls like
FB.api(
'/me/albums',
'GET',
{},
function(response) {
// Insert your code here
console.log(response);
console.log(token);
}
);
我正在追踪 firebase上的文档进行身份验证。用户已成功创建用户已授予照片访问权限的防火墙。我只是无法弄清楚如何使用令牌来打电话给Facebook的图形API。
I am following the documentation on firebase to make the authentication. The user is successfully created on firebase the user has given permission for photo access. I just am not able to figure out how to use the token to makes calls to Facebook's graph api.
var provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('user_photos');
provider.addScope('user_friends');
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Facebook Access Token. You can use it to access the Facebook API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
编辑
当我在重定向后进行通话得到以下错误
EDIT When I make the call after the redirect I get the following error
"An active access token must be used to query information about the current user."
推荐答案
你可以做什么@luschn说或你也可以用facebook api做一个简单的http请求。
You could do what @luschn said or you could also make a simple http request with facebook api.
$.get(
"https://graph.facebook.com/me",
{
'fields' : fields,
'access_token' : token
},
function(response) {
//enter code here
}
)
您可以从Facebook的图形API获取字段,访问令牌是您获得的从firebase。
You can get the fields from facebook's graph api and access token is the one you got from firebase.
这篇关于使用firebase认证令牌使用JS SDK进行图形API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!