GAPI 未定义 [英] GAPI Is Not Defined

查看:29
本文介绍了GAPI 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 Google javascript api 加载到我的 chrome 扩展程序中遇到了很多麻烦.请注意,我对 javascript 非常陌生,甚至对 chrome 扩展程序也很陌生.

I am having much trouble getting the Google javascript api to load in my chrome extension. Please note I am very new to javascript and even newer to chrome extensions.

我有一个执行脚本的 background.js 文件

I have a background.js file which executes a script

chrome.tabs.executeScript(null, { file: "ChromeExtension.js" });

这个ChromeExtension.js文件如下

This ChromeExtension.js file then look as follows

//Call Initialize Method
init();

//Function To Initial Chrome Extension
function init(){
    var clientID = 'Client ID';
    var apiKey = 'API Key';
    var scopes = 'https://www.googleapis.com/auth/plus.me';

    loadGAPIClient();

    gapi.client.setApiKey(apiKey);


}

我的问题是在

gapi.client.setApiKey(apiKey);

我得到 gapi 未定义 事情是一旦我的 ChromeExtension.js 完成执行,gapi 已完全定义并且可用.

I get gapi is not defined The thing is once my ChromeExtension.js has completed execution, gapi is fully defined and available.

我在一些堆栈溢出问题中尝试了其他建议,但无济于事.我相信这是由于缺乏 Javascript 知识,但如果有人能够提供一些帮助,我将不胜感激.

I have tried other suggestions in some stack overflow questions but to no avail. I believe this is due to lack of Javascript knowledge but I would be grateful if anyone would be able to provide some assistance.

感谢您的宝贵时间.

编辑 - 当前 GAPI 加载

EDIT - Current GAPI Load

function () loadGAPIClient(){
    var s = document.createElement("script");
        s.type = "text/javascript";
        s.src = "https://apis.google.com/js/client.js";
        $("head").append(s);
}

此函数在我的 init() 中调用,我也对其进行了更新以反映这一点.

This function is called in my init(), which I have also updated to reflect this.

我也尝试过使用 jQuery.getScript 等方法.

I have also tried using jQuery.getScript among other ways.

请理解这是我的问题,我找不到正确加载 GAPI 客户端的方法

Please understand this is my issue, I cannot find a way to correctly load the GAPI Client

推荐答案

孤立世界 问题.

具体来说,您的 loadGAPIClient 添加一个

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆