gpt4 book ai didi

javascript - 不为自托管 chrome 扩展的 chrome.identity.getAuthToken 调用回调

转载 作者:行者123 更新时间:2023-11-30 10:01:00 26 4
gpt4 key购买 nike

我正在开发一个自托管的 chrome 扩展程序,并已按照描述生成了 key 和 client_id here .我对 getAuthToken 的调用是(从 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 注册我的应用程序(而不是使用自行生成的 key 对、key 和 client_id)才能调用我的回调?对于向 google 注册的测试应用程序,正确调用了相同的回调。

我的 list 文件有

    "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。还要确保您的产品有一个可以在同意屏幕下填写的名称。选择已安装的应用程序和 Chrome 应用程序:

enter image description here

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

关于javascript - 不为自托管 chrome 扩展的 chrome.identity.getAuthToken 调用回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31693754/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com