Advertisement
notjacob

lol

Mar 13th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         System.out.println(getUserInfo("joshmcsquash").getDisplayName());
  3.     }
  4.  
  5.     /**
  6.      * will always select the first user with that name (even if there are multiple)
  7.      * @param name
  8.      * @return
  9.      */
  10.     public static BungieUser getUserInfo(String name) {
  11.         try {
  12.             String url = "https://www.bungie.net/platform/Destiny2/SearchDestinyPlayer/-1/" + name;
  13.             HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
  14.             con.setRequestMethod("GET");
  15.             con.addRequestProperty("X-API-KEY", api_key);
  16.             InputStreamReader reader = new InputStreamReader(con.getInputStream());
  17.             JsonElement parse = JsonParser.parseReader(reader);
  18.             JsonObject obj = parse.getAsJsonObject();
  19.             if (obj.get("Response").isJsonArray()) {
  20.                 JsonObject userJS =  obj.getAsJsonArray("Response").get(0).getAsJsonObject();
  21.                 return new BungieUser(userJS.get("crossSaveOverride").getAsInt(), userJS.get("isPublic").getAsBoolean(), userJS.get("membershipType").getAsInt(),
  22.                         userJS.get("membershipId").getAsLong(), userJS.get("displayName").getAsString(), userJS.toString());
  23.             }
  24.         } catch (IOException e) {
  25.             e.printStackTrace();
  26.         }
  27.         return null;
  28.     }
  29.  
  30.  
  31. // returns
  32.  
  33. {
  34.     "iconPath":"/img/theme/bungienet/icons/psnLogo.png",
  35.     "crossSaveOverride":0,
  36.     "isPublic":false,
  37.     "membershipType":2,
  38.     "membershipId":"4611686018435142467",
  39.     "displayName":"Joshmcsquash"
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement