我正在尝试检索经过身份验证的用户博客(授予范围(:
var token = await firebase.auth().currentUser.getIdToken();
fetch('https://www.googleapis.com/blogger/v3/users/self/blogs', {
"headers": {
"Authorization": "Bearer " + token
},
"method" : "GET",
"muteHttpExceptions": true
}).then( r => console.log(r) );
但我得到错误:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Invalid Credentials",
"domain": "global",
"reason": "authError",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
你能告诉我在不使用后端的情况下实现这一目标我缺少什么吗?
Firebase身份验证ID令牌是JWT。Blogger需要一个OAuth 2令牌,而Firebase Authentication令牌不是。
虽然在Firebase中可以基于OAuth令牌创建ID令牌,但反过来是不可能的。您将不得不使用OAuth 2提供程序登录用户,并将该令牌传递给blogger。