gpt4 book ai didi

java - 使用 Web-API 和 Java 接受 Steam 的交易报价

转载 作者:行者123 更新时间:2023-11-30 03:17:07 24 4
gpt4 key购买 nike

我有一个 Java Steam 贸易机器人,它可以读取 Steam 的待处理贸易报价,并根据要求拒绝它们。我正在使用官方 Web API(使用 http://steamcommunity.com/dev/apikey 中的 API key )向 Steam 传达请求。变量 trade 来 self 自己的 API 接口(interface)(我已对其进行了调试,适用于拒绝报价)。

SteamPlug.steamRequest(method, query); 只是一个基本的 HTTP 请求程序:

public static String steamRequest(String method, String query) {
try {
URL obj = new URL(query);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

con.setRequestMethod(method);

int responseCode = con.getResponseCode();

if (responseCode != 200 && responseCode != 201) {
return "ERR" + responseCode;
}

BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

return response.toString();
} catch (MalformedURLException | ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
// Ignored
}

return null;
}

这就是它拒绝贸易报价的方式:

SteamPlug.steamRequest(
"POST",
"http://api.steampowered.com/IEconService/DeclineTradeOffer/v0001/?key="
+ SteamPlug.API_KEY + "&tradeofferid=" + trade.getTradeOfferId()
);

我想做的也是接受交易。我已经尝试过:

SteamPlug.steamRequest(
"POST",
"https://steamcommunity.com/tradeoffer/" + trade.getTradeOfferId() + "/accept?key="
+ SteamPlug.API_KEY
);

但我收到了 411 Length required 响应。

我相信我可以通过使用 Steam session 身份验证来接受报价,但是是否可以仅使用用户的 Web-API key 来接受交易报价?

最佳答案

您阅读过 Steam API 文档吗?没有交易接受功能,所以我假设你不能通过 API 接受交易。您的选择是检查 SteamBot(尽管它是用 C# 编写的)交易功能,并考虑对 steam 站点的直接 http 请求(我相信具有适当的 steam 身份验证)。我自己目前正在编写一个机器人,但现在阻止我的一件事是接受交易。

关于java - 使用 Web-API 和 Java 接受 Steam 的交易报价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32300321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com