0

我正在尝试检索经过身份验证的用户博客(授予范围):

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"
  }
}

你能告诉我在不使用后端的情况下我缺少什么吗?

4

1 回答 1

0

Firebase 身份验证 ID 令牌是 JWT。Blogger 需要一个 OAuth 2 令牌,而 Firebase 身份验证令牌不是。

虽然可以在 Firebase 中基于 OAuth 令牌创建 ID 令牌,但反过来是不可能的。您必须改为使用 OAuth 2 提供者登录用户,然后将该令牌传递给博主。

于 2020-11-26T02:56:02.820 回答