我正在为我的 chrome 扩展使用react-chrome-redux 堆栈。我已经尝试过日历 API 中的 Javascript/Node.js 快速入门,但它们不起作用。
所以现在我尝试通过 Chrome Identity API 检索 oAuth2 令牌,然后发出 HTTP 请求来获取我的数据。
清单.json
"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}
Run Code Online (Sandbox Code Playgroud)
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);
})
})
Run Code Online (Sandbox Code Playgroud)
我设法从 oAuth2 令牌中获取一长串字符,但是当我尝试发出 …