gpt4 book ai didi

javascript - 使用 firebase 身份验证 token 使用 JS SDK 进行图形 api 调用

转载 作者:行者123 更新时间:2023-11-30 08:31:18 32 4
gpt4 key购买 nike

我目前有一个 Facebook 应用程序,该应用程序使用 firebase 对我的应用程序进行身份验证和登录。我正在使用 firebase 身份验证获取访问 token 。我想使用这个 token 来调用 graph api,比如

FB.api(
'/me/albums',
'GET',
{},
function(response) {
// Insert your code here
console.log(response);
console.log(token);
}
);

我正在关注 documentation on firebase进行认证。用户已在 firebase 上成功创建,用户已授予照片访问权限。我只是无法弄清楚如何使用 token 来调用 Facebook 的图形 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;
// ...
});

编辑当我在重定向后调用电话时,出现以下错误

"An active access token must be used to query information about the current user."

最佳答案

你可以按照@luschn 所说的去做,或者你也可以用 facebook api 发出一个简单的 http 请求。

$.get(
"https://graph.facebook.com/me",
{
'fields' : fields,
'access_token' : token
},
function(response) {
//enter code here
}
)

您可以从 facebook 的 graph api 获取字段,访问 token 是您从 firebase 获取的。

关于javascript - 使用 firebase 身份验证 token 使用 JS SDK 进行图形 api 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37637972/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com