Google Oauth2.0:

Google Oauth2.0:

我将 Google NodeJS 客户端示例与 DialogFlow 执行服务器一起使用:https://github.com/google/google-api-nodejs-client/tree/master/samples

生成了我的 Google API Web 客户端凭据,我将 url 重定向到 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 时,我被定向到一个网站并提示我登录 google 帐户。我有以下错误:

keys.redirect_uris[0] , TypeError: Cannot read property '0' of undefined

DialogFlow 执行服务器也在 运行ngrok 地址上。

5 月 24 日更新:

登录 google 帐户后:

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>)

如果您实际上是想 运行 oauth2.js,请确保 oauth2.keys.json 文件与 oauth2.js 文件。如果您只是使用 oauth2.js 作为生成您自己的令牌的示例,您可以修改文件以从对您有意义的任何位置读取密钥。