如何修复 Google 日历 API 错误
How to fix Google Calendar API error
我正在关注 https://developers.google.com/google-apps/calendar/quickstart/nodejs#step_3_set_up_the_sample
但它不起作用并输出如下:
var clientSecret = credentials.installed.client_secret;
^
TypeError: Cannot read property 'client_secret' of undefined
at authorize (/Users/prangyy/myApp/quickstart.js:32:43)
at processClientSecrets (/Users/prangyy/myApp/quickstart.js:21:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)
尝试在 Node.js Quickstart 中检查您的 client_secret.json。
应该包含clientID, auth_url, token_uri, auth_provider_x509_cert_url, client_secret, redirect_uris, javascript_origins.
{"web":{"client_id":"YOUR_CLIENT_ID","project_id":"google.com:my-project-1231","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":"YOUR_CLIENT_SECRET","redirect_uris":["YOUR_REDIRECT"],"javascript_origins":["YOUR_JAVA_ORIGIN"]}}
如果还没有,请按照此步骤获取您的 client_secret.json
文件
- Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
- At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
- Select the Credentials tab, click the Create credentials button and select OAuth client ID.
- Select the application type Other, enter the name "Google Calendar API Quickstart", and click the Create button.
- Click OK to dismiss the resulting dialog.
- Click the file_download (Download JSON) button to the right of the client ID.
- Move this file to your working directory and rename it client_secret.json.
希望对您有所帮助。祝你好运:)
将 quickstart.js 中的第 34-36 行更改为:
var clientSecret = credentials.web.client_secret;
var clientId = credentials.web.client_id;
var redirectUrl = credentials.web.redirect_uris[0];
(他们使用 credentials.installed
而不是 credentials.web
的错误出现在 client_secrets.json 文件中。)
如果您在选择应用程序类型[=14=时勾选'其他'(如教程中所述),则无需修改原始代码] 在客户端 ID 创建页面(粘贴文本的第 4 步)
我正在关注 https://developers.google.com/google-apps/calendar/quickstart/nodejs#step_3_set_up_the_sample
但它不起作用并输出如下:
var clientSecret = credentials.installed.client_secret;
^
TypeError: Cannot read property 'client_secret' of undefined
at authorize (/Users/prangyy/myApp/quickstart.js:32:43)
at processClientSecrets (/Users/prangyy/myApp/quickstart.js:21:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)
尝试在 Node.js Quickstart 中检查您的 client_secret.json。
应该包含clientID, auth_url, token_uri, auth_provider_x509_cert_url, client_secret, redirect_uris, javascript_origins.
{"web":{"client_id":"YOUR_CLIENT_ID","project_id":"google.com:my-project-1231","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":"YOUR_CLIENT_SECRET","redirect_uris":["YOUR_REDIRECT"],"javascript_origins":["YOUR_JAVA_ORIGIN"]}}
如果还没有,请按照此步骤获取您的 client_secret.json
文件
- Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
- At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
- Select the Credentials tab, click the Create credentials button and select OAuth client ID.
- Select the application type Other, enter the name "Google Calendar API Quickstart", and click the Create button.
- Click OK to dismiss the resulting dialog.
- Click the file_download (Download JSON) button to the right of the client ID.
- Move this file to your working directory and rename it client_secret.json.
希望对您有所帮助。祝你好运:)
将 quickstart.js 中的第 34-36 行更改为:
var clientSecret = credentials.web.client_secret;
var clientId = credentials.web.client_id;
var redirectUrl = credentials.web.redirect_uris[0];
(他们使用 credentials.installed
而不是 credentials.web
的错误出现在 client_secrets.json 文件中。)
如果您在选择应用程序类型[=14=时勾选'其他'(如教程中所述),则无需修改原始代码] 在客户端 ID 创建页面(粘贴文本的第 4 步)