gpt4 book ai didi

google-chrome-extension - chrome.identity.getAuthToken 不起作用

转载 作者:行者123 更新时间:2023-12-03 22:05:48 30 4
gpt4 key购买 nike

我正在使用 Chrome Identity API,在我的 Chrome 扩展程序上为用户提供 Google 身份验证。

我跟着谷歌的官方教程:link Chrome Identity API

  • 我为 添加了权限manifest.json 客户端 ID 范围
  • 为了触发身份验证,我在 中添加了此代码Background.js

  • 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 控制台中更新它

    enter image description here

    关于google-chrome-extension - chrome.identity.getAuthToken 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31141573/

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