【发布时间】:2021-02-02 07:23:15
【问题描述】:
我正在尝试使用 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”)。那么为什么缺少重定向 URL?也许这是我在运行该设置时遗漏的东西?此外,这些说明暗示我正在为自己的日历设置一个 API,而我想做一个 API 来读取别人的日历。他们将其显示在网页上,因此是公开的。 (见我贴的相关问题:Can I use Google Calendar API v3 to access someone else's public calendar without auth?)
【问题讨论】:
标签: node.js google-api google-calendar-api