Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- System.out.println(getUserInfo("joshmcsquash").getDisplayName());
- }
- /**
- * will always select the first user with that name (even if there are multiple)
- * @param name
- * @return
- */
- public static BungieUser getUserInfo(String name) {
- try {
- String url = "https://www.bungie.net/platform/Destiny2/SearchDestinyPlayer/-1/" + name;
- HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
- con.setRequestMethod("GET");
- con.addRequestProperty("X-API-KEY", api_key);
- InputStreamReader reader = new InputStreamReader(con.getInputStream());
- JsonElement parse = JsonParser.parseReader(reader);
- JsonObject obj = parse.getAsJsonObject();
- if (obj.get("Response").isJsonArray()) {
- JsonObject userJS = obj.getAsJsonArray("Response").get(0).getAsJsonObject();
- return new BungieUser(userJS.get("crossSaveOverride").getAsInt(), userJS.get("isPublic").getAsBoolean(), userJS.get("membershipType").getAsInt(),
- userJS.get("membershipId").getAsLong(), userJS.get("displayName").getAsString(), userJS.toString());
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- // returns
- {
- "iconPath":"/img/theme/bungienet/icons/psnLogo.png",
- "crossSaveOverride":0,
- "isPublic":false,
- "membershipType":2,
- "membershipId":"4611686018435142467",
- "displayName":"Joshmcsquash"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement