我正在使用 Chrome Identity API,在我的 Chrome 扩展程序上为用户提供 Google 身份验证。
我跟着谷歌的官方教程:link Chrome Identity API
chrome.identity.getAuthToken
问题是当我执行扩展时我被重定向到这个登录页面
chrome://chrome-signin/?source=5
但在成功验证后,我再次被重定向到登录页面
问题是什么 ?
list 文件
{
"name": "My Extension",
"short_name": "Ex App",
"version": "0.1",
"description": "description",
"manifest_version": 2,
"icons": { "128": "ICONE.png", "48": "ICONE1.png" },
"permissions": ["contextMenus", "identity", "cookies", "http://*/*", "https://*/*", "<all_urls>", "unlimitedStorage"],
"browser_action": {
"default_title": "Title",
"default_icon": "imgIcone.png"
},
"oauth2": {
"client_id": "xxxxxxx",
"scopes": [
"https://www.googleapis.com/auth/userinfo.email"
]
},
"background": {
"scripts": ["background.js"]
},
"content_scripts" : [
{
"matches": ["*://*.google.com/*"],
"js": ["gadget/js/jquery.js","gadget/js/contactcard.js"],
"css": ["gadget/css/contactcard.css"],
"all_frames": true
}],
"content_security_policy": "script-src 'self' 'unsafe-eval' https://apis.google.com/; object-src 'self'",
"web_accessible_resources": ["img.png","gadget/css/contactcard.css","gadget/img/extension/crec.png"]
}
背景.js:
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
// Use the token.
console.log(token);
});
最佳答案
问题已解决!
应用 ID 我的 Chrome extension
与我的不匹配 应用 ID 在 Google Console Developpers
为了避免这种上传,您的扩展程序首先从 Chrome 复制 ID 并在 Google 控制台开发人员中设置它!
每次在 Google Chrome 中更改它时,您都必须在 Google 控制台中更新它
关于google-chrome-extension - chrome.identity.getAuthToken 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31141573/