0

我以为我的事情正在滚动,但我发现在使用 interactive:false 调用 getAuthToken 后出现了这个错误:

OAuth2 请求失败:服务响应错误:“错误请求”

'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 );
    }
});

我很乐意提供任何其他可能有助于确定我哪里出错的信息。

4

1 回答 1

0

Chrome 文档中说明了交互式对象中布尔值的目的/含义,获取令牌可能需要用户登录 Chrome,或批准应用程序请求的范围。如果interactive标志是truegetAuthToken将根据需要提示用户。当标志是false或省略时,getAuthToken将在需要提示时返回失败。

现在为你的错误OAuth2 request failed: Service responded with error: 'Bad Request'

确保在创建 OAuth 凭据时在同意屏幕中提供电子邮件地址和产品名称。

有关更多信息,请查看此线程

于 2016-08-09T09:58:19.950 回答