我在頁面加載時按谷歌的文檔,運行這段代碼:GAPI在內容腳本未定義
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
這是我的代碼:
gapi.auth.authorize({
'client_id': 'my_client_id',
'immediate': 'false',
'response_type':'token',
'scope': 'https://www.googleapis.com/auth/userinfo.email'
}, function() {
console.log(arguments);
});
在控制檯,如果我訪問gapi
我看到了物體。但是,如果我在該代碼塊中使用斷點,則gapi
未定義。現在,我粘貼在這裏的代碼通過內容腳本加載。如何將gapi
庫加載到內容腳本中?
在我運行依賴'gapi'的代碼之前,客戶端對象('gapi')存在。由於某些原因,在內容腳本中訪問它時,該對象不存在。有任何想法嗎? – dopatraman 2014-09-22 00:29:43