简体   繁体   English

使用 node.js 获取 Steam 社区市场价格历史

[英]Get Steam Community Market price history with node.js

I'm having trouble getting the price history of an item from Steam.我在从 Steam 获取物品的价格历史记录时遇到问题。 By looking at other questions I've managed to learn a nifty way to construct a link which indeed gives me the price history of an item, my problem is that you have to be logged in to Steam to aquire this data.通过查看其他问题,我设法学会了一种构建链接的绝妙方法,该链接确实为我提供了物品的价格历史记录,我的问题是您必须登录 Steam 才能获取此数据。 How do I view this data as if I'm logged in through an http-request?我如何查看这些数据,就好像我通过 http 请求登录一样? I've read other threads where they talked about browser sessions and how someone in my situation should set cookies of ones session-id but I haven't managed to get it to work in node.我已经阅读了其他线程,他们谈到了浏览器会话以及在我的情况下应该如何设置会话 ID 的 cookies 但我还没有设法让它在节点中工作。 The status code I'm getting is 400.我得到的状态码是 400。

This is my code:这是我的代码:

const https = require('https');

const options = {
  host: 'steamcommunity.com',
  path: '/market/pricehistory/?country=SE&currency=3&appid=730&market_hash_name=CS20%20Case',
  method: 'GET',
  headers: {
    'Cookie': `steamLoginSecure=THE SESSION ID I GOT FROM WRITING
              "document.cookie" IN THE DEV CONSOLE`
  }
}

const req = https.request(options, res => {
  console.log(res.statusCode);
  console.log(res.headers);

  let body = '';

  res.on('data', data => {
    body += data;
  });

  res.on('end', () => console.log(body));
}).on('error', error => console.log(error));
req.end();

I'm not sure if there's anything wrong in my code or how to go about to solve this issue I'm having.我不确定我的代码是否有任何问题,或者如何 go 来解决我遇到的这个问题。 I really appreciate any help I can get.我非常感谢我能得到的任何帮助。

It seems like Steam has removed the 'steamLogin' cookie, thus explaining why so many people this past year have been encountering issues when using it in their code.似乎 Steam 已经删除了“steamLogin”cookie,从而解释了为什么去年有这么多人在他们的代码中使用它时遇到了问题。 Instead, you want to use the 'steamLoginSecure' cookie.相反,您想使用“steamLoginSecure”cookie。

First you need be logged in to https://steamcommunity.com .首先,您需要登录到https://steamcommunity.com Second you want to find the 'steamLoginSecure' cookie and copy what it contains.其次,您要找到“steamLoginSecure”cookie 并复制其中包含的内容。 For chrome that would be:对于铬,这将是:

Settings > Advanced > Privacy and security > Site Settings > Cookies and site data > See all cookies and site data > steamcommunity.com > steamLoginSecure设置 > 高级 > 隐私和安全 > 站点设置 > Cookies 和站点数据 > 查看所有 cookies 和站点数据 > steamcommunity.com > steamLoginSecure

Now copy the content of 'steamLoginSecure' and have it as a cookie in your headers.现在复制“steamLoginSecure”的内容并将其作为 cookie 放在您的标题中。

This is the final code I ended up with:这是我最终得到的最终代码:

const https = require('https');

const options = {
  host: 'steamcommunity.com',
  path: '/market/pricehistory/?country=SE&currency=3&appid=730&market_hash_name=CS20%20Case',
  method: 'GET',
  headers: {
    'Cookie': 'steamLoginSecure=THE CONTENT OF "steamLoginSecure" HERE'
  }
}

const req = https.request(options, res => {
  console.log(res.statusCode);
  console.log(res.headers);

  let body = '';

  res.on('data', data => {
    body += data;
  });

  res.on('end', () => console.log(body));
}).on('error', error => console.log(error));
req.end();

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

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