Google chrome extension 来自chrome扩展的Google日历API HTTP请求
我正在使用react chrome redux堆栈作为我的chrome扩展。 我已经尝试了Calendar API中的Javascript/Node.js快速入门,但它们不起作用 所以现在我试图通过Chrome Identity API检索oAuth2令牌,然后发出HTTP请求以获取数据 manifest.jsonGoogle chrome extension 来自chrome扩展的Google日历API HTTP请求,google-chrome-extension,google-calendar-api,Google Chrome Extension,Google Calendar Api,我正在使用react chrome redux堆栈作为我的chrome扩展。 我已经尝试了Calendar API中的Javascript/Node.js快速入门,但它们不起作用 所以现在我试图通过Chrome Identity API检索oAuth2令牌,然后发出HTTP请求以获取数据 manifest.json "oauth2": { "client_id": "CLIENT_ID.apps.googleusercontent.com", "scopes": [
"oauth2": {
"client_id": "CLIENT_ID.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly"
]
},
"key": APP_KEY}
HTTP请求
chrome.identity.getAuthToken({ 'interactive': false }, function(token) {
var init = {
'method' : 'GET',
'async' : true,
'headers': {
'Authorization' : 'Bearer ' + token,
'Content-Type': 'application/json'
},
'contentType': 'json'
};
fetch('https://www.googleapis.com/calendar/v3/calendars/public/events', init)
.then((response) => response.json()) // Transform the data into json
.then(function(data) {
console.log(data);
})
})
我设法从oAuth2令牌中获取一个长字符串,但是当我尝试发出HTTP请求时,我得到一个404状态错误
我已经寻找了很长一段时间关于堆栈溢出的问题,但大多数问题都没有得到很好的回答,而且似乎没有一种简单的方法从chrome扩展中使用API
我真的希望有人能帮我,谢谢 @furydevoid发现了这一点 原来默认的日历关键字是“primary”而不是“public” 现在我对HTTP请求执行以下操作:
const headers = new Headers({
'Authorization' : 'Bearer ' + token,
'Content-Type': 'application/json'
})
const queryParams = { headers };
fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', queryParams)
.then((response) => response.json()) // Transform the data into json
.then(function(data) {
console.log(data);
})
})
对于任何试图通过chrome扩展使用Google日历API的人
加载资源失败:服务器响应状态为404()
,打印返回的数据会给我一个错误
对象。背景页:没有错误日志。我的扩展覆盖了新的标签页,现在我把代码放在新的标签页上。