【问题标题】:Authorizing YouTube API to chrome extension授权 YouTube API 到 chrome 扩展
【发布时间】:2018-04-30 06:43:43
【问题描述】:

我尝试连接 youtube API 以在“browser_action”弹出窗口中使用它。 youtube API page 中有一个快速入门指南。有一个 HTML 代码,可以复制粘贴试试,如果它可以工作,以后再使用。

使用外部 .js 文件(youtube API)时会出现问题,它给了我错误:

Refused to load the script 'https://apis.google.com/js/api.js' because it 
violates the following Content Security Policy directive: "script-src 'self' 
blob: filesystem: chrome-extension-resource:".

没关系,here 我们可以了解它为什么会这样工作。在本文后面,它说明了将文件包含到项目中的最佳方式。在这种情况下比较困难,因为 api.js 里面有更多的链接,而这个文件不能完成这项工作。

稍后在article 中写道,我们可以将一些来源添加到白名单中,这样就可以从外部来源加载它。我认为这应该可以解决问题,所以我已将其添加到清单中。

 "content_security_policy": "script-src 'self' https://apis.google.com/js/api.js; object-src 'self'", 

( 也尝试了其他版本,例如“https://apis.google.com/*”等,但没有任何区别,仍然出现相同的错误。

那里有什么问题?将 apis.google.com 列入白名单可以完成这项工作还是不好的方法?以及如何正确地做到这一点。

我添加了完整清单,可能有错误

  {
    "manifest_version": 2,

    "name": "YT Gniewos tryhards",
    "description": "This extension was made to learn and to try some things with youtube.",
    "version": "1.0",

    "content_security_policy": "script-src 'self' https://apis.google.com/*; object-src 'self'",
    "browser_action": {
      "default_icon": "icon.png",
      "default_popup": "qucikstart.html",
      "default_title": "Click here!"
    },
    "permissions": [
      "activeTab",
      "storage"
    ]
  }

【问题讨论】:

    标签: javascript google-chrome-extension youtube-api


    【解决方案1】:

    Create OAuth 2.0 credentials 用于 Chrome。

    您需要为您的 Chrome 应用或扩展程序指定 Application ID。使用 Google Chrome Identity API 获取该 ID。

    【讨论】:

      猜你喜欢
      • 2015-05-28
      • 2021-01-14
      • 2015-08-15
      • 2011-08-25
      • 1970-01-01
      • 2013-07-04
      • 2015-09-14
      • 2012-11-29
      • 1970-01-01
      相关资源
      最近更新 更多