JnCrMx / discord-game-sdk4j

Java bindings for Discord's Game SDK
MIT License
123 stars 23 forks source link

Discord SDK download returns 403 #22

Closed DeDiamondPro closed 3 years ago

DeDiamondPro commented 3 years ago

Hi, I just started using this but quite quickly ran in to an issue, when I try to download the SDK from the discord servers it returns a 403, So I was wondering if I'm doing something wrong, there is a problem with the libary or there is a problem with discord.

I'm just using the example code for dowloading the SDK.

JnCrMx commented 3 years ago

This is caused by Discord (or Cloudflare) trying to block automated requests. They seem to block the User-Agent sent by some Java versions, but allow some others.

You could try to set the User-Agent to a common value (e.g. a Firefox version) to avoid this problem.

URL downloadUrl = new URL("https://dl-game-sdk.discordapp.net/2.5.6/discord_game_sdk.zip");

URLConnection connection = downloadUrl.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");

ZipInputStream zin = new ZipInputStream(connection.getInputStream());

(see https://github.com/JnCrMx/MinecraftDiscordLobbies/blob/1.16.4/src/main/java/com/github/JnCrMx/discordlobbies/DiscordLobbiesMod.java#L60 for an example)

DeDiamondPro commented 3 years ago

that seems to do the trick, thanks!