继承我的代码:
var google = googleapis;
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2('xxxxxx', 'xxxxxxx', 'https://bt-feedback.meteor.com/oauth2');
oauth2Client.setCredentials({
access_token: 'xxxxxxxx',
refresh_token: 'xxxxxxxx'
});
google.options({ auth: oauth2Client }); // set auth as a global default
var calendar = google.calendar('v3');
calendar.events.watch({
calendarId: 'xxxxxxxxxxx'
},
{
id: 'xxx-xx-xx-xx-xxxxxxxxxx',
address: 'https://bt-feedback.meteor.com/notifications',
type: 'web_hook'
}, function(err, res) {
console.log("err, res:", err, res);
});
这是我一直得到的错误:
W20150128-16:12:24.574(-7)? (STDERR) { errors:
W20150128-16:12:24.576(-7)? (STDERR) [ { domain: 'global',
W20150128-16:12:24.576(-7)? (STDERR) reason: 'required',
W20150128-16:12:24.576(-7)? (STDERR) message: 'entity.resource' } ],
W20150128-16:12:24.576(-7)? (STDERR) code: 400,
W20150128-16:12:24.576(-7)? (STDERR) message: 'entity.resource' }
任何想法都会出现!?我检查了一堆差异问题,但似乎没有任何帮助。
答案 0 :(得分:2)
我遇到了同样的问题。我没有时间弄清楚为什么googleapis模块在这一点上没有工作,但我得到了直接的API请求。
request.post('https://www.googleapis.com/calendar/v3/calendars/[calendarName]/events/watch',{
headers:{
Authorization:'Bearer '+oauth2Client.credentials.access_token
,'content-type':'application/json'
}
,json:true
,body:{
id:[channelId]
,type:'web_hook'
,address:[callbackUrl]
}},callback);