我关注了 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/