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

标签 google-chrome-extension google-oauth google-chrome-app

我正在使用 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/

    相关文章:

    google-chrome-extension - Chrome : Webview not resizing

    javascript - 如何使 Chrome 扩展程序的未捕获异常处理程序工作(由于 CORS 保护而不起作用)

    oauth-2.0 - 如何在 Dart 中使用 Oauth2 在 Google Fusion Tables 中进行身份验证?

    google-analytics - Google Analytics Reporting API v4缺少必需的身份验证凭据

    javascript - Chrome 28 应用程序,getUserMedia PERMISSION_DENIED

    javascript - Chrome 扩展程序,来自字符串的文件?

    javascript - Chrome 扩展程序的分析事件跟踪

    php - Google OAuth - 私有(private) IP 需要 device_id 和 device_name

    html - 如何在移动 Chrome 应用程序中使用音频

    javascript - 是否可以删除 "Inspect Element"?