我正在使用带有DialogFlow履行服务器的Google NodeJS客户端示例:https://github.com/google/google-api-nodejs-client/tree/master/samples。
生成我的Google API Web客户端凭据,我的重定向网址为https://xxxxxx.ngrok.io
然后下载了JSON并重命名为样本文件夹中的oauth2.keys.json。
{
"web": {
"client_id": "XXXXX.apps.googleusercontent.com",
"project_id": "XXXX",
"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": "XXXX",
"redirect_uris": ["https://XXXX.ngrok.io"]
}
}
当我运行节点oauth2.js时,我被引导到一个网站并被提示登录谷歌帐户。我有以下错误:
keys.redirect_uris [0],TypeError:无法读取属性' 0'未定义的
DialogFlow履行服务器也在ngrok地址运行。
更新24可以:
登录谷歌帐户后:
Headers {
"host": "xxxx.ngrok.io",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/xx.x.xxxx.xxx Safari/537.36",
"accept": "image/webp,image/apng,image/*,*/*;q=0.8",
"referer": "https://xxxxxxx.ngrok.io/?code=xxxxxxxxxxxxxxxxxxxxxxxxx",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"x-forwarded-proto": "https",
"x-forwarded-for": "xxx.xx.xx.xxx"
}
TypeError: Cannot read property 'payload' of undefined
at getRequest (/Users/xxxxx/Desktop/facts/functions/node_modules/actions-on-google/dist/service/dialogflow/conv.js:30:45)
at new DialogflowConversation (/Users/xxxxx/Desktop/facts/functions/node_modules/actions-on-google/dist/service/dialogflow/conv.js:37:22)
at Function.<anonymous> (/Users/xxxxxx/Desktop/facts/functions/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:113:24)
at Generator.next (<anonymous>)
at /Users/xxxxxxx/Desktop/facts/functions/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:22:71
at new Promise (<anonymous>)
at __awaiter (/Users/xxxxx/Desktop/facts/functions/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:18:12)
at Function.handler (/Users/xxxxx/Desktop/facts/functions/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:84:16)
at Object.<anonymous> (/Users/xxxxxx/Desktop/facts/functions/node_modules/actions-on-google/dist/assistant.js:55:32)
at Generator.next (<anonymous>)
答案 0 :(得分:1)
如果您确实尝试运行 oauth2.js,请确保oauth2.keys.json
文件与oauth2.js文件位于同一目录中。如果您仅使用oauth2.js作为生成自己的令牌的示例,则可以修改该文件以从任何对您有意义的位置读取密钥。