Reputation: 7832
Following googleapis documentation I've retrieved tokens including refresh_token
:
{ access_token: 'ya29.Glv_LONG-STRING',
token_type: 'Bearer',
refresh_token: '1/7k6BLAH-BLAH-BLAH',
expiry_date: 1532141656948 }
How can I get list of Google Calendar events using this when access_token
is not valid anymore, but I have the refresh_token
?
Upvotes: 1
Views: 156
Reputation: 201388
You have already retrieved the refresh token. You want to retrieve an event list using Calendar API by the refresh token. If my understanding is correct, how about this sample script? In this script, it supposes the following points.
https://www.googleapis.com/auth/calendar
or https://www.googleapis.com/auth/calendar.readonly
for retrieving the event list using Calendar API in the scopes.When you run the script, if the error occurs, please confirm above points.
const {google} = require('googleapis');
const calendar = google.calendar('v3');
var oauth2Client = new google.auth.OAuth2(
"### client ID ###",
"### client secret ###",
);
oauth2Client.setCredentials({
refresh_token: "### refresh token ###",
// access_token: "#####" // If you want to use access token, please use this.
});
calendar.events.list({
auth: oauth2Client,
calendarId: 'primary',
}, function(err, res) {
if (err) {
console.log(err);
} else {
console.log(res.data);
}
});
calendarId
for your environment.If I misunderstand your question, I'm sorry.
Upvotes: 1