'How to check if the google access token has been revoked
I'm using the google node js api to check a user's availability. How do I check to see if the user's access token has been revoked? I would like to send him an email if that's the case.
Here's what I have
var defer = Q.defer(); // get a new deferral
oauth2Client.setCredentials({
refresh_token: refreshToken,
});
const calendar = google.calendar({version: "v3", auth: oauth2Client});
calendar.freebusy.query(
{
auth: oauth2Client,
resource: {
timeMin: new Date(startDate).toISOString(),
timeMax: new Date(endDate).toISOString(),
items: [{id: "primary"}],
},
},
(err, response) => {
if (err) {
console.dir(err);
console.log(
"There was an error obtaining availability from google calendar service " +
err
);
defer.reject(err);
return;
}
let events = null;
if (
response &&
response.data &&
response.data.calendars &&
response.data.calendars.primary &&
response.data.calendars.primary.busy
) {
events = response["data"]["calendars"]["primary"]["busy"];
}
if (!events) {
defer.resolve(false);
} else {
defer.resolve(events);
}
}
);
return defer.promise; // return a promise
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
