When developing the Alexa skill. I'm trying to use Axios get to get the whole day's events information from google calendar api. When I redo the account linking, it works well. I thought the asscessToken could only last for 2 hours, and I get the 401 error message because the token is expired.
Here is my Axios code
const getEvents = async (url, accessToken) => {
try {
const config = {
headers: {'Authorization': 'Bearer ' + accessToken}
};
return await Axios.get(url, config);
} catch (error) {
console.log('Error getting events');
console.error(error);
}
}
Code for my url and the asscesstoken
const url = EVENTS_URL + "?orderBy=updated&timeMin=" + timeMin + "&timeMax="
+ timeMax;
const accessToken =
handlerInput.requestEnvelope.context.System.user.accessToken;
Error Message:
ERROR { Error: Request failed with status code 401
at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15)
at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:260:11)
at IncomingMessage.emit (events.js:203:15)
at IncomingMessage.EventEmitter.emit (domain.js:448:20)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
method: 'get',
headers:
{ Accept: 'application/json, text/plain, */*',
Authorization: 'Bearer undefined',
'User-Agent': 'axios/0.21.1' },