简体   繁体   English

从第三方网站API获得价值

[英]Getting a value from 3rd party website API

So I'm desperately trying to pull a value from a 3rd party website API. 因此,我拼命尝试从第三方网站API获取值。 The information is formatted in the following way: 该信息的格式如下:

Website's API response 网站的API响应

I'd like to pull out a value for "price". 我想提取“价格”的值。 So far I've tried many different codes but all have failed. 到目前为止,我已经尝试了许多不同的代码,但是都失败了。 I've also spent a lot of time searching for a solution but without succes. 我也花了很多时间寻找解决方案,但没有成功。 At the moment my code for obtaining the value looks like this, but it's obviously not complete and incorrect as I'm new to NodeJs: 目前,我用于获取值的代码如下所示,但是由于我是NodeJ的新手,它显然不完整且不正确:

var Request = require("request");
Request.get("url", (error, response, body) => {
    if(error) {
        return console.dir(error);
    }
    console.dir(JSON.parse(body));
});

And yes the url is actually inserted in my code + I know that this should only display the full JSON structure, but it fails to do even that :/ 是的,实际上是在我的代码中插入了url +我知道这应该只显示完整的JSON结构,但即使这样,它也无法实现:/

Any kind of advice would be welcome :) 任何建议都将受到欢迎:)

EDIT: So I've fixed that issue with not getting data :) However I still need to filter my data in order to pull out the "price" value. 编辑:所以我已经解决了不获取数据的问题:)但是,我仍然需要过滤我的数据以提取“价格”值。 As of now my data displays this: "data: { items_on_sale: [ [Object] ], items_not_on_sale: [] } }" 到目前为止,我的数据显示如下:“数据:{items_on_sale:[[Object]],items_not_on_sale:[]}}”

status: 'fail' : The api is not replying with the data.Does the url require any query params/body to be passed with the url? status:'fail' :api没有回复数据。URL是否要求将任何查询参数/正文与URL一起传递?

Try hitting the api using postman/SoapUI and check the response there. 尝试使用postman / SoapUI击中api并检查响应。

also try printing the response in the log,what values do you get? 还尝试在日志中打印响应 ,您会得到什么值?

console.log('statusCode:', response && response.statusCode); 

There was a problem with 2FA code. 2FA代码有问题。 It wasn't generating properly. 它生成不正确。 It is now fixed. 现在已修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM