google-chrome-extension - Chrome 扩展标识 : OAuth2 request failed: Service responded with error: 'bad request'

标签 google-chrome-extension google-sheets-api google-oauth

我关注了 https://developer.chrome.com/extensions/tut_oauth完全一步一步,但我被困在

https://developer.chrome.com/extensions/tut_oauth#identity_permission

在我执行我的扩展后,我得到的不是 token ,而是错误:

Unchecked runtime.lastError while running identity.getAuthToken: 
OAuth2 request failed: Service responded with error: 'bad request'

请提出此错误的可能原因。

最佳答案

tl;博士

如果为空,则将范围更新为以下内容,

 "oauth2": {
    "client_id": "yourExtensionOAuthClientIDWillGoHere.apps.googleusercontent.com",
    "scopes":["https://www.googleapis.com/auth/userinfo.email"]
  }

关注 OAuth2: Authenticate Users with Google 上的教程的人

如果您遇到此问题,可能是因为现在是 2020 年,文档没有更新。

本教程要求您,

Include the "oauth2" field in the extension manifest. Place the generated OAuth client ID under "client_id". Include an empty string in "scopes" for now.

{
  "name": "OAuth Tutorial FriendBlock",
  ...
  "oauth2": {
    "client_id": "yourExtensionOAuthClientIDWillGoHere.apps.googleusercontent.com",
    "scopes":[""]
  },
  ...
}


但在调用身份 API 调用以获取 token 之前永远不会更新它。

更新范围,使用以下内容应该可以解决问题,
"scopes": ["https://www.googleapis.com/auth/userinfo.email"]

关于google-chrome-extension - Chrome 扩展标识 : OAuth2 request failed: Service responded with error: 'bad request' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51619276/

相关文章:

android - 如何在一个 Activity 中登录和退出 Google

google-chrome - 谷歌登录 "error": "popup_closed_by_user"

javascript - 丰富的通知不起作用

javascript - 将大型 JSON/JS 对象从内容脚本压缩到 background.js - chrome 扩展

javascript - 返回 Google 表格中事件单元格的行

javascript - Mailchimp Google Sheet 与 api key 的问题

google-chrome-extension - manifest.json, content_scripts 限制与带端口号的 url 的匹配

javascript - 代码在 Chrome 控制台中运行良好,但在 Chrome 扩展程序中运行不正常

google-apps-script - 如何将 Google Apps 脚本/表格作为值从一个电子表格复制并粘贴到另一个电子表格?

python - 通过云功能访问 Google 表格 Python API 的身份验证问题