没有为自托管 chrome 扩展的 chrome.identity.getAuthToken 调用回调

Callback not called for chrome.identity.getAuthToken for self hosted chrome extension

我正在开发一个自托管的 chrome 扩展程序,并已生成密钥和 client_id 所描述的 here. My call to getAuthToken is (copied from the answer to this question)

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

但是我发现当用户被正确定向到 google 登录页面时,我的回调从未被调用 在用户被正确验证后。我的问题:我是否必须使用 Google(而不是使用自生成的密钥对、密钥和 client_id)注册我的应用程序才能调用我的回调?对于使用 google 注册的测试应用程序,正确调用了相同的回调。

我的清单文件有

    "permissions": [
        "background",
        ...
        "identity",
        "*://*/*"
    ],
    "key" : "Long key here",
    "oauth2" : {
            "client_id" : "Id of length 32",
            "scopes" : [
                "https://www.googleapis.com/auth/plus.login"
            ]
    }

谢谢。

你用错了client id。 生成有效的 client id:

转到 https://console.developers.google.com 并在凭据下创建一个 client id。还要确保您的产品有一个可以在同意屏幕下填写的名称。 Select 已安装的应用程序和 Chrome Application:

现在从 chrome://extensions/ 复制您的扩展程序 ID 并将其粘贴到 detail/ 之后,然后单击创建客户端 ID。将生成您的客户端 ID,现在将此客户端 ID 复制并粘贴到您的 manifest.json