【发布时间】:2016-08-08 10:12:52
【问题描述】:
我以为事情在发生,但我发现在使用 interactive:false 调用 getAuthToken 后出现此错误:
OAuth2 请求失败:服务响应错误:'Bad Request'
'Bad Request' 真的很少告诉我。好的,我知道我可能需要使用 interative:true (为什么?),所以当我尝试这样做时,它会生成我的浏览器,提示我的谷歌登录(我输入它,这真的很痛苦,因为我们有两步身份验证),然后……什么都不做……回调永远不会被调用……
任何有兴趣帮助我的人都可能希望从我的 manifest.json 中查看位:
"key": "MII...QAB",
"oauth2": {
"client_id": "35...-lnf...1pd.apps.googleusercontent.com",
"scopes": [ "identity" ]
},
"permissions":[ "identity", "https://accounts.google.com/*", "https://www.googleapis.com/*", "https://*.amazonaws.com/*", "<all_urls>" ],
您可能还想查看相关代码:
chrome.identity.getAuthToken({ 'interactive': true, 'scopes':['identity'] }, function ( token ) {
if ( chrome.runtime.lastError ) {
next(chrome.runtime.lastError);
} else {
next( null, token );
}
});
或者,或者:
chrome.identity.getAuthToken({ 'interactive': false }, function ( token ) {
if ( chrome.runtime.lastError ) {
next(chrome.runtime.lastError);
} else {
next( null, token );
}
});
我很乐意提供任何其他可能有助于确定我哪里出错的信息。
【问题讨论】:
-
这意味着与浏览器已经登录的 chrome 会话(在 chrome://settings 上登录的会话)一起使用,如果您已经在那里登录,它将允许单击授权.
-
@kzahel :是的,我理解那部分。它确实提示我登录(尽管我已经登录)......然后它什么也不做,除非我设置 interactive:false 否则永远不会调用回调(带令牌)......然后它告诉我“错误请求” (没有足够的信息继续......)
标签: javascript google-chrome-app google-identity