首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌云平台Node.js库

谷歌云平台Node.js库
EN

Stack Overflow用户
提问于 2018-04-17 05:59:52
回答 1查看 178关注 0票数 3

我正在创建一个google功能。然而,当我尝试部署到Google平台时,我会得到这个错误

错误:(gcloud.beta.functions.deploy) OperationError: code=3,message=Function加载错误:无法加载index.js文件中的代码。在package.json依赖项中列出了所有必需的模块吗?详细堆栈跟踪:错误:找不到模块‘请求’

如何在google云平台上上传/安装“请求”库?

代码段

代码语言:javascript
复制
'use strict';
const https = require('https');
const host = 'https://www.example.com';
const clientId = 'qpopMIGtVdeIdVk3oEtr2LGbn8vTeTWz';
const clientSecret = 'eUnsWQ8y3AuiFHJu';
const grant_type = 'client_credentials';
const resource = 'b.microsoft.com/4fa4b4a7-d34f-49af-8781-c8b39f0cf770';
const request = require("request");


exports.oauthtoken = (req, res) => {

  // Call the Apigee API
  callGetOAuthToken().then((output) => {
    // Return the results from the APigee  to DialogFlow
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({ 'speech': output, 'displayText': output }));
  }).catch((error) => {     
        // If there is an error let the user know
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({ 'speech': error, 'displayText': error }));
  });
};
function callGetOAuthToken () {
  return new Promise((resolve, reject) => {

    let path = '/customers/v1/accesstoken';

    var authHeader =  Buffer.from(clientId + ':' + clientSecret).toString('base64');
    var post_options = {
                          url: host + path,
                          method: 'POST',
                          headers: 
                          {
                            'Content-Type': 'application/x-www-form-urlencoded',
                            'Authorization': 'Basic ' + authHeader,
                            'grant_type':grant_type
                          }
                        };

    // Make the HTTP request to get the weather
    request(post_options, function(err, res, body) {
        let output = JSON.parse(body);
        console.log(output);
        resolve(output);
      });   
  });
}

-艾伦-

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-17 06:15:19

阅读Google关于依赖关系的文档:https://cloud.google.com/functions/docs/writing/dependencies

如果使用gcloud,请将“请求”模块作为package.json文件中的依赖项列出。

或者,在包含云功能的文件夹中运行“npm安装-保存请求”,并将预安装的依赖项上传为ZIP文件的一部分。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49870892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档