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.
I have a background.js file which executes a script
chrome.tabs.executeScript(null, { file: "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);
}
My problem is that at
gapi.client.setApiKey(apiKey);
I get gapi is not defined The thing is once my ChromeExtension.js has completed execution, gapi is fully defined and available.
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.
Thank you for your time.
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);
}
This function is called in my init(), which I have also updated to reflect this.
I have also tried using jQuery.getScript among other ways.
Please understand this is my issue, I cannot find a way to correctly load the GAPI Client
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…