Search in sources :

Example 1 with EpicLookup

use of com.xilixir.fortniteapi.v2.Epic.EpicLookup in project FortniteAPI by Xilixir.

the class FortniteAPI method getUserInfo.

public EpicLookup getUserInfo(String username) throws IOException {
    // request
    GenericUrl url = new GenericUrl("https://persona-public-service-prod06.ol.epicgames.com/persona/api/public/account/lookup?q=" + username);
    HttpRequest request = factory.buildGetRequest(url);
    // headers
    request.getHeaders().setAuthorization("bearer " + this.auth.getAccessToken());
    String json = request.execute().parseAsString();
    EpicLookup lookup = new Gson().fromJson(json, EpicLookup.class);
    log("Looked up user '" + lookup.getDisplayName() + "{" + lookup.getId() + "}'");
    return lookup;
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) Gson(com.google.gson.Gson) GenericUrl(com.google.api.client.http.GenericUrl) EpicLookup(com.xilixir.fortniteapi.v2.Epic.EpicLookup)

Example 2 with EpicLookup

use of com.xilixir.fortniteapi.v2.Epic.EpicLookup in project FortniteAPI by Xilixir.

the class Example method main.

public static void main(String[] args) {
    Configuration login = new Configuration("login", Credentials.class);
    Credentials credentials = login.read();
    FortniteAPI api = new FortniteAPI(credentials);
    try {
        api.authenticate();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        EpicLookup lookup = api.getUserInfo("bad.player");
        Friend[] friends = api.getFriendListData(lookup.getId());
        for (Friend friend : friends) {
            if (friend.getStatus() == Status.PENDING && friend.getDirection() == Direction.INBOUND) {
                System.out.println("attempting to delete friend: " + new Gson().toJson(friend));
                api.deleteFriendRequest(lookup.getId(), friend.getAccountId());
            }
        }
        System.out.println(new Gson().toJson(friends));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Configuration(com.xilixir.fortniteapi.v2.Configuration) Friend(com.xilixir.fortniteapi.v2.Epic.Friends.Friend) Gson(com.google.gson.Gson) IOException(java.io.IOException) FortniteAPI(com.xilixir.fortniteapi.v2.FortniteAPI) Credentials(com.xilixir.fortniteapi.v2.Credentials) EpicLookup(com.xilixir.fortniteapi.v2.Epic.EpicLookup)

Aggregations

Gson (com.google.gson.Gson)2 EpicLookup (com.xilixir.fortniteapi.v2.Epic.EpicLookup)2 GenericUrl (com.google.api.client.http.GenericUrl)1 HttpRequest (com.google.api.client.http.HttpRequest)1 Configuration (com.xilixir.fortniteapi.v2.Configuration)1 Credentials (com.xilixir.fortniteapi.v2.Credentials)1 Friend (com.xilixir.fortniteapi.v2.Epic.Friends.Friend)1 FortniteAPI (com.xilixir.fortniteapi.v2.FortniteAPI)1 IOException (java.io.IOException)1