chrome.identity.getAuthToken时无效的OAuth2客户端ID

时间:2015-06-29 08:13:14

标签: google-chrome-extension google-api

我按照这个问题给出的答案 - chrome.identity User Authentication in a Chrome Extension

我安装了扩展程序并从chrome://extensions复制了密钥并生成了客户端ID enter image description here

enter image description here

生成客户端ID和应用程序ID后,我将其粘贴到manifest.json

我的manifest.json -

{

    "name": "Identity test",
    "version": "1",
    "manifest_version": 2,
    "background": {
        "scripts": ["background.js"]
    },  
    "permissions": [
        "identity"
    ],
     "oauth2": {
        "client_id": "575910104810-bip578sprqmaauj7cred8ejsf3cirs95.apps.googleusercontent.com",
        "scopes": [
            "https://www.googleapis.com/auth/userinfo.email"
        ]   
    },   
    "key":"mebmekhndfhnahepihccnkiaifobgdbi"

}

我的background.js -

chrome.identity.getAuthToken({
    interactive: true
}, function(token) {
    if (chrome.runtime.lastError) {
        alert(chrome.runtime.lastError.message);
        return;
    }
    var x = new XMLHttpRequest();
    x.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token);
    x.onload = function() {
        alert(x.response);
    };
    x.send();
});

但是我收到了无效的OAuth2客户端ID。原因?

1 个答案:

答案 0 :(得分:1)

清单中"key"字段的格式无效。

它不是ID,而是加密签名的版本。

有关如何获取正确值的信息,请参阅herehere

相关问题