我嘗試從Chrome擴展程序連接到我的本地主機服務的Google Endpoints API。我設法將OAuth轉換爲Google Contact API,而不是通過其JS客戶端,但使用https://apis.google.com/js/client.js?onload=loadF
從不調用回調函數。當我試圖手動調用它時,在控制檯中出現錯誤: Refused to execute inline event handler because it violates the following Content Security Policy directive
。看起來後臺工作者沒有足夠的權限來加載API,但是從控制檯沒有關於它的信息。如何從Chrome擴展程序使用Google Enpoints
我的JS代碼
var apiRoot='//localhost:8080/_ah/api';
var loadF = function() {
console.log("api init");
gapi.client.load('my_api', 'v1', function(){
console.log("callback");
}, apiRoot);
}
我的清單:
{
"name": "Linkeer",
"version": "1.0",
"description": "Linkeer ",
"manifest_version": 2,
"icons": {
"128": "icon128.png"
},
"browser_action": {
"default_title": "OAuth 2.0",
"default_icon": "icon128.png",
"default_popup": "options.html"
},
"options_page": "options.html",
"content_scripts": [
{
"matches": ["http://www.google.com/robots.txt*"],
"js": ["oauth2/oauth2_inject.js"],
"run_at": "document_start"
}
],
"permissions": [
"https://accounts.google.com/o/oauth2/token",
"http://localhost:8080/_ah/api"
],
"web_accessible_resources" : [
"oauth2/oauth2.html"
],
"content_security_policy": "script-src 'self' http://localhost https://apis.google.com https://www.googleapis.com; object-src 'self'"
}
會很高興,如果有人可以幫助我這個問題。
如果您將最低限度的代碼量進行了複製,我會仔細研究一下。 – abraham