用户已经使用Google操作中的谷歌登录授权他的gmail帐户。现在我需要向用户谷歌日历插入事件列表,但我面临一些问题或者不知道如何构建它。我很新的日历api所以请任何人指导我如何解决它。
const {google} = require('googleapis');
var calendar = google.calendar('v3');
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
const client_secret = "xyz";
const client_id = "xyz";
const redirect_uris ="xyz";
const oAuth2Client = new google.auth.OAuth2(
client_id, client_secret, redirect_uris);
oAuth2Client.setCredentials({
access_token: 'ACCESS TOKEN HERE'
});
var event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
};
calendar.events.insert({
auth: oAuth2Client,
calendarId: 'primary',
resource: event,
}, function(err, event) {
if (err) {
console.log('There was an error contacting the Calendar service: ' + err);
return;
}
});
使用Google Sign In for Assistant获得的ID令牌不足以让您访问其日历。您将需要访问令牌或身份验证令牌。虽然谷歌登录有助于此 - 它不是完整的图片,解决方案可能有点复杂。
通常,您需要执行以下操作:
有关该过程的更完整的讨论,请参见this StackOverflow post。