标签: rapidapi

RapidAPI 响应正文显示为“未定义”

我正在使用 RapidAPI 中的 webcams.travel API(API 文档链接),并且我已经使用 browserify、unirest、node、require 等设置了所有内容。

API 响应采用 json 格式,并且正在输出响应标头,但响应正文应该为我提供一个带有网络摄像头的对象,但它显示为“未定义”。这是我现在的输出:

控制台输出的图像

是json解析的问题,还是和unirest有关系?我很感谢任何帮助。

我的 app.js 中的代码(这是 API 站点建议的请求片段):

var unirest = require('unirest');

unirest.get("https://webcamstravel.p.rapidapi.com/webcams/list/continent=AN?lang=en&show=webcams%3Aimage%2Clocation")
.header("X-RapidAPI-Key", "MY_RAPID_API_KEY")
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});
Run Code Online (Sandbox Code Playgroud)

javascript api json undefined rapidapi

5
推荐指数
1
解决办法
1569
查看次数

尝试通过 swift 访问rapidAPI yahoo Finance 时出现错误 403

我正在尝试使用rapidAPI 访问个人项目的雅虎财经API。我注册了一个免费帐户并获得了 API 密钥。Rapid API 允许用户复制和粘贴代码来请求数据,因此我使用了他们的演示代码来访问 API。这是为了快速访问股票的详细信息:

import Foundation

let headers = [
"x-rapidapi-host": "apidojo-yahoo-finance-v1.p.rapidapi.com",
"x-rapidapi-key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" //private key 
]

let request = NSMutableURLRequest(url: NSURL(string: "https://apidojo-yahoo-finance- 
v1.p.rapidapi.com/stock/get-detail?region=US&lang=en&symbol=APPL")! as URL,
                                    cachePolicy: .useProtocolCachePolicy,
                                timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
    if (error != nil) {
        print(error)
    } else {
        let httpResponse = response as? HTTPURLResponse
        print(httpResponse)
    }
})

dataTask.resume()
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,它给出错误 403。这意味着根据他们的网站 …

api yahoo-finance swift rapidapi

5
推荐指数
1
解决办法
4076
查看次数

节点:内部/错误:464 ErrorCaptureStackTrace(错误);

当我尝试在 .env 文件中添加安全 API 密钥时,出现以下错误:

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-RapidAPI-Host"
    at ClientRequest.setHeader (node:_http_outgoing:579:3)
    at new ClientRequest (node:_http_client:256:14)
    at Object.request (node:https:353:10)
Run Code Online (Sandbox Code Playgroud)

下面是我的代码:

const axios = require("axios");

const BASE_URL = `https://mashape-community-urban-dictionary.p.rapidapi.com`

module.exports = {
    getCompatibility: (yourSearch) => axios({
        method:"GET",
        url : BASE_URL + `/define`,
        headers: {
          'X-RapidAPI-Host': process.env.rapidapi_host,
          'X-RapidAPI-Key': process.env.Rrapidapi_key
        },
        params: {
            term: yourSearch
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

我的环境文件:

rapidapi_host={my secure host}
rapidapi_key={my secure key}
Run Code Online (Sandbox Code Playgroud)

谁能解释为什么会发生这种情况?

javascript node.js rapidapi

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

rapidapi ×3

api ×2

javascript ×2

json ×1

node.js ×1

swift ×1

undefined ×1

yahoo-finance ×1