【问题标题】:Google Oauth2.0:谷歌 Oauth2.0:
【发布时间】:2018-11-02 06:10:40
【问题描述】:

我正在使用带有 DialogFlow 实现服务器的 Google NodeJS 客户端示例: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"]
    }
}

当我运行 node oauth2.js 时,我被定向到一个网站并被提示登录到一个谷歌帐户。我有以下错误:

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

DialogFlow 实现服务器也在 ngrok 地址运行。

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

【问题讨论】:

    标签: node.js oauth-2.0 dialogflow-es google-api-nodejs-client


    【解决方案1】:

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

    【讨论】:

    • 是的,在同一个目录下。正是因为如此,我不太清楚为什么会发生错误。是否在考虑重定向 uri (url) 是否错误?
    猜你喜欢
    • 2021-07-28
    • 2014-07-24
    • 1970-01-01
    • 2018-12-15
    • 2018-11-27
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多