【发布时间】:2015-08-30 19:28:52
【问题描述】:
我有一个 Java Steam 贸易机器人,它读取来自 Steam 的待处理贸易报价并根据要求拒绝它们。我正在使用官方 Web API(使用来自 http://steamcommunity.com/dev/apikey 的 API 密钥)向 Steam 传达请求。变量 trade 来自我自己的 API 接口(我已对其进行调试并适用于拒绝报价)。
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 会话身份验证来接受报价,但是否可以仅使用用户的 Web-API 密钥来接受交易报价?
【问题讨论】:
标签: java steam-web-api