我正在尝试使用谷歌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\u secret.JSON”)。那么为什么重定向URL丢失了呢?也许这是我运行该设置时遗漏的内容?此外,这些指示意味着我正在为自己的日历设置一个API,在这里我想做一个API来读取其他人的日历。他们将其显示在网页上,因此它是公开的。(见我发布的相关问题:
Can I use Google Calendar API v3 to access someone else's public calendar without auth?
)