微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从 Parse Server 云代码 Parse.Cloud.httpRequest 中正确验证 Google API?

如何解决如何从 Parse Server 云代码 Parse.Cloud.httpRequest 中正确验证 Google API?

我一直试图弄清楚如何使用我的 Google 服务帐户在 Parse.Cloud.httpRequest 中对我的 Google Api 进行身份验证,此处针对各种环境进行了描述:https://cloud.google.com/docs/authentication/production#auth-cloud-explicit-nodejs 另外,作为参考,{{ 3}} 描述了如何通过 REST 与 DialogFlow 交互。我可以使用 curl 从我的命令行成功获得来自 Dialogflow 的响应。解析云代码是我卡住的地方:我已将 googleapis npm 模块添加到 back4app cloud package.json。我不确定如何正确使用 Parse.Cloud.httpRequest 中的 google 服务帐户密钥(以 .json 文件的形式)作为标头中“授权”密钥的一部分。当我按原样(如下)运行时,我得到一个未定义/空的响应。有没有人成功做到这一点?

const googleServiceAccountKey = './<my .json google service account key file>';

Parse.Cloud.define("df-test",(request) => {
    Parse.Cloud.httpRequest({
        method: 'POST',url: 'https://dialogflow.googleapis.com/v2/projects/<my-project-id>/agent/sessions/1234567:detectIntent',headers: {
        'Content-Type': 'application/json','Authorization' : 'Bearer ' + googleServiceAccountKey,},body: {
            "query_input": {
                "text": {
                  "text": "Hello","language_code": "en-US"
                }
              }
        }
        }).then(function(httpResponse) {
        console.log(httpResponse.text);
        },function(httpResponse) {
        console.error('Request Failed with response code ' + httpResponse.status);
    });
 });

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。