我正在尝试使用Google API访问其他人的公开日历。
我的代码 - 摘自此页:https://developers.google.com/google-apps/calendar/quickstart/nodejs
function authorize(credentials, callback) {
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
console.log ("credentials.installed=" +
JSON.stringify(credentials.installed));
var redirectUrl = credentials.installed.redirect_uris[0];
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
错误和控制台输出(为安全性而更改了JSON的值):
λ node testGoogleCalendarAPI.js
credentials.installed={"client_id":"123412341234-whatever.apps.googleusercontent.com","project_id":"app-name-187323","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"whatever"}
E:\GitHub\NealWalters\RabbiJoseph\testGoogleCalendarAPI.js:62
var redirectUrl = credentials.installed.redirect_uris[0];
^
TypeError: Cannot read property '0' of undefined
at authorize (E:\GitHub\NealWalters\RabbiJoseph\testGoogleCalendarAPI.js:62:56)
at processClientSecrets (E:\GitHub\NealWalters\RabbiJoseph\testGoogleCalendarAPI.js:49:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:447:3)
上面的JSON来自我在上面引用的URL上运行步骤后下载的文件(并保存为'client_secret.json')。那么为什么缺少重定向网址?也许这是我在运行该设置时遗漏的东西?此外,说明暗示我正在为我自己的日历设置API,在那里我想要一个API来阅读别人的日历。它们显示在网页上,因此它是公开的。 (参见我发布的相关问题:Can I use Google Calendar API v3 to access someone else's public calendar without auth?)