Tag: api

通过NodeJS调用远程API,并将结果附加到我的API失败

我正在尝试从CA API调用一个API,该API以格式p7b的附件forms返回证书文件。 我需要附加到我的API并返回到我的客户端。 我是NodeJS的新手,我无法得到这个工作。 有人可以帮忙吗? 我试过res.pipe(),它没有工作。 我在下面给出了我的代码片断。 app.get("/api/certificate/:certificateid", function (req, res) { var certificateId = req.params.certificateid; var header = { "X-DC-DEVKEY": apiKey, "Content-Type": "application/json" }; var options = { host: certUrl, port: 443, method: 'GET', path: 'xxxxx/certificate/' + certificateId + '/download/format/p7b', headers: header }; https.request(options, function (res1) { // res1.setEncoding('gzip'); DID NOT WORK res1.on('data', function […]

React w / SignalR – TypeError:WebSocketClient()不是一个构造函数

React开发新function 我正在为BitTrex Exchange API构build一个API客户端,使用它们的node.js包装器: node.bittrex.api 为了在ReactJS框架中简单地testing订单更新的websocket订阅,下面是我采取的步骤: – 使用创build反应 – 应用程序来创build应用程序。 -used npm安装node.bittrex.api – 将bittrex客户端对象添加到默认App.js组件的顶部,并使用适当的API密钥configuration选项 – 添加一个button(与处理程序绑定到buttonReact文档)到默认的App.js主要组件, 在处理函数中,根据node.bittrex.api文档中的示例代码启动websocket订阅。 该应用程序出现了,但是当我按下button,我得到一个错误,说TypeError Websocketclient()不是一个构造函数,在创buildwebsocket连接的SignalR.js中的行: 现在我怀疑只有一些与React框架有关的东西正在搞砸了。 任何人都可以帮助我理解错综复杂的东西吗? 谢谢。 这是我的App.js: import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; var bittrex = require('../node_modules/node.bittrex.api/node.bittrex.api.js'); bittrex.options({ 'apikey' : process.env.REACT_APP_BTREX_API_KEY, 'apisecret' : process.env.REACT_APP_BTREX_SECRET_KEY, 'verbose' : true, 'cleartext' : false, 'baseUrl' : […]

使用phoenix_api_docs

我想用https://github.com/smoku/phoenix_api_docs来创build一个doc api,但是我遇到了一个问题,正如文档中所指出的那样,我把test_helper.exs放在了这里: PhoenixApiDocs.start ExUnit.start(formatters: [ExUnit.CLIFormatter, PhoenixApiDocs.Formatter]) 当我运行混合testing,控制台显示我这样的: 09:22:51.173 [error] GenEvent handler PhoenixApiDocs.Formatter installed in #PID<0.323.0> terminating ** (UndefinedFunctionError) function WhitespaceEx.Application.Router.__routes__/0 is undefined (module WhitespaceEx.Application.Router is not available) WhitespaceEx.Application.Router.__routes__() (phoenix_api_docs) lib/phoenix_api_docs/generator.ex:26: PhoenixApiDocs.Generator.routes_docs/2 (phoenix_api_docs) lib/phoenix_api_docs/generator.ex:12: PhoenixApiDocs.Generator.run/0 (phoenix_api_docs) lib/phoenix_api_docs/formatter.ex:22: PhoenixApiDocs.Formatter.save_blueprint_file/0 (phoenix_api_docs) lib/phoenix_api_docs/formatter.ex:9: PhoenixApiDocs.Formatter.handle_event/2 (stdlib) gen_event.erl:573: :gen_event.server_update/4 (stdlib) gen_event.erl:555: :gen_event.server_notify/4 (stdlib) gen_event.erl:296: :gen_event.handle_msg/6 (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 Last message: {:suite_finished, […]

GET请求的参数数组

例如:我们有以下操作: GET /employees 我必须具有允许使用多个名称作为参数进行筛选的function。 我代表它如下所示: GET /employees?empNames=xxx,yyy,zzz 但是,现在我没有一个名为empName的参数,而是我有两个参数empFirstName和empSurname。 其中将如下所示: GET /employees?empFirstName=xx&empSurname=x 但我仍然需要API来接受多个名称(empFirstName和empSurname)filter。 我可以看到几种方式来表示它: GET /employees?name=(xx,x),(yy,y),(zz,z) GET /employees?name=xx:x,yy:y,zz:z GET /employees?name=[{empFirstName=xx, empSurname=yy},{empFirstName=yy, empSurname=zz},{empFirstName=aa, empSurname=bb}] 什么可能是这种过滤最好的宁静表示。 有什么标准你需要在URI中使用分隔符:a,还是其他的? 什么是最简单和最好的方法来做到这一点?

我如何做一个try / catch为我的特定API调用示例?

所以我的问题是非常具体的。 每当我从我的页面运行这个位,我得到一个错误,如果我不input我需要在API中search正确的ID。 由于查询string不正确,它不知道该做什么,因此无法进行有效的API调用。 如何redirect到不同的页面?如果有这样的错误,或者如何阻止它停止程序? 我假设有一个尝试在这里,但我尝试了多种不同的方式,我仍然困惑,因为它不工作。 请帮助! 我是新来的…这是片段。 如果“bnetID”不是有效的ID,则代码的请求部分是发生错误的地方。 如果它是有效的,它运行得非常好… // Make a GET request to the /results page (When submit is pressed) app.get("/results", function(req, res){ // Retrieve bnetID and REGION from the FORM var bnetID = req.query.bnetID; var region = req.query.region; // Replace the # with a – bnetID = bnetID.replace("#", "-"); // Create the […]

从维基百科API获取SVG文件

我正在尝试在node.js中使用Wikipedia API。 只有知道所有图像的类别,才有可能从维基百科API获取SVG文件 ?

节点js适合于批量更新

我在节点上写了一个脚本来与2个系统连接,并使用api将一堆更新应用到一个。 使用个别的例子更新工作正常,但是当把它们放在一起我得到一个超时错误。 由于节点的非阻塞性质而导致的猜测,即使用数千次更新来洪泛系统可能是问题。 我是否选错了使用的工具/引擎? 如果是的话,我的path是什么样的阻力最小(是否有其他的JavaScript环境,我可以重新使用我的代码?或者有没有办法设置某种深度的队列,以保持传出请求的数量没有响应较低)

访问被拒绝创build电子表格Google节点API

我正在使用google节点API来生成电子表格。 我使用的第三方库是官方的( https://github.com/google/google-api-nodejs-client )。 以下是我用来生成电子表格的代码: var sheets = google.sheets('v4'); sheets.spreadsheets.create({ auth: auth, resource: { properties:{ title: "Google export" } } }, (err, response) => { if (err) { console.log('The API returned an error: ' + err); return; } else { console.log("Added"); res.send(response); } }); 它工作正常,并生成工作表,当我显示响应对象,我得到的电子表格的链接: spreadsheetUrl:“ https://docs.google.com/spreadsheets/d/1XS_QHxPUQcGqZGAzFHkHZV-RSKsv5IpJazcjVpLTYkk/edit ” 但是,当我尝试在浏览器中打开它时,我不能: You need permission 。 事情是,如果我点击Request accessbutton,我认为它实际上从我的凭据(user@project-174309.iam.gserviceaccount.com)发送一个请求到client_email […]

将video上传到节点中的url

在我的应用程序中,我想发布一个video到多个networking(fb,twitter …),我正在上传video到cloudinary,它发回的url,我用来张贴到fb。 对于Twitter,无法通过url发布video。 有没有其他办法可以做到这一点? 我的服务器尺寸很低,如1-2GB,所以我不能下载video到我的服务器,然后创build一个stream上传到Twitter。 我担心,如果3-4名用户开始上传,那么我的服务器将崩溃,内存不足。 任何build议使用twit包或简单的HTTP请求是受欢迎的。 谢谢

节点JS请求 – 承诺POST方法不能识别一个string

为了连接我的node.js模块与另一台服务器,我使用'request-promise'库。 当我想发布这样的东西: rp.({ method: 'POST', headers:{ 'Content-Type': 'text/plain', 'Authorization': '' }, uri: 'https://myendpoint.com', body:{ name: 'here is my a name', code: 'here is my code', location: 'here is my location' } }).then(…) 但总是当我尝试使用这个function,我得到这样的错误信息: RequestError: Error: Argument, error, options.body. TypeError: First argument must be a string or Buffer 我所有的身体参数都是string。 此外,我也尝试了相同的邮递员方法,并为我工作。 那么我做错了什么?