Google chrome extension gapi.auth.authorize不适用于Google Chrome扩展

Google chrome extension gapi.auth.authorize不适用于Google Chrome扩展,google-chrome-extension,oauth-2.0,Google Chrome Extension,Oauth 2.0,下面是我的分机代码。我试图通过Oauth2授权访问Google API,但是当扩展调用gapi.auth.authorize()函数时,我收到错误消息“TypeError:cannot read property'authorize'of undefined”。有什么问题吗 舱单: { "manifest_version": 2, "name": "name", "description": "description", "version": "1.0", "content_secu

下面是我的分机代码。我试图通过Oauth2授权访问Google API,但是当扩展调用gapi.auth.authorize()函数时,我收到错误消息“TypeError:cannot read property'authorize'of undefined”。有什么问题吗

舱单:

{
"manifest_version": 2,

"name": "name",
"description": "description",
"version": "1.0",

    "content_security_policy": "script-src 'self' https://apis.google.com/js/client.js; object-src 'self'",
"browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
}
}
HTML:


您的
内容\u安全\u策略
应更新为
“脚本src'self”https://apis.google.com/;对象src“self”
。加载API会触发回调,该回调需要单个URL之外的文件。您甚至可能需要进一步扩展安全策略,这取决于授权需要下面瀑布的其他方面


您是否尝试过查看API?它可能会更好。我在某个地方读到,如果我使用chrome.identity,我必须发布Google web store的扩展,我真的不想这样做。上面的评论不是真的,但如果有多个用户安装它,这将使它变得更难。看看官方示例,有一个完整的oauth示例。这是来自的官方示例,我仍然得到相同的错误,然后我将清单更新为
“script src'self'https://;object src'self'”
,以便更好地衡量,我仍然得到相同的错误。我不相信您可以简单地将所有https源代码都列为白名单。我将策略更新为“脚本src'self”https://apis.google.com/ https://accounts.google.com https://oauth.googleusercontent.com https://ssl.gstatic.com;对象src“self”基于上面屏幕截图中的流程,但从OAuth获得以下错误:
拒绝显示'https://accounts.google.com/o/oauth2/auth?.....authuser=0'在框架中,因为它将'X-frame-Options'设置为'SAMEORIGIN'。
在框架中使用popup.html的标准OAuth过程可能不可行。
<!doctype html>
<html>
  <head>    
    <script type="text/javascript" src="https://apis.google.com/js/client.js"></script>
    <script type="text/javascript" src="processform.js"></script>
  </head>
  <body>
    <form name="myform">
         First name: <input type="text" id="fname" name="firstname" /><br />
         Last name:  <input type="text" id="lname" name="lastname" /><br />
        <input name="Submit"  type="submit" value="Update" />
    </form>
  </body>
</html>
var CLIENT_ID = ' ... .apps.googleusercontent.com';
var SCOPES = [
  'https://www.googleapis.com/auth/drive.file',
];

function handleClientLoad() {
    checkAuth();
}

function checkAuth() {
    try {
        gapi.auth.authorize(
            {'client_id': CLIENT_ID, 'scope': SCOPES.join(' '), 'immediate': true},
            handleAuthResult);
    }
    catch(err) {
        var e = err.toString();
        alert(e);
    }
}


function handleAuthResult(authResult) {
    if (authResult) {
    } else {
        gapi.auth.authorize(
            {'client_id': CLIENT_ID, 'scope': SCOPES.join(' '), 'immediate': false},
            handleAuthResult);
}
}

function ExampleJS(){
 }


 document.addEventListener('DOMContentLoaded', function () {
  handleClientLoad();
});

 document.addEventListener('DOMContentLoaded', function () {
  document.forms["myform"].addEventListener('submit', ExampleJS);
});