Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get images api to work #2

Open
GregDake opened this issue Jul 13, 2019 · 1 comment
Open

Can't get images api to work #2

GregDake opened this issue Jul 13, 2019 · 1 comment

Comments

@GregDake
Copy link

I'm trying to get the images api to work to download custom images of the characters from the help api, but get FileNotFound exceptions regardless of what characters I ask for, what options I give (rarity, level, zeta) or whether they are toons or ships.

I don't see any documentation on the image api at https://api.swgoh.help/swgoh so it is hard for me to tell what the requested url should be nor try it with just a curl command, so I'm unsure if the issue is with .help or with the wrapping api.

The error message is always of the form:

Caused by: java.io.FileNotFoundException: https://api.swgoh.help/image/char/DARTHTRAYA?level=85&gear=12&rarity=7

Below the simplest main I could come up with that demonstrates the issue. I'm using version 4.2.1 of the api, but it was failing with 4.1.0 as well.

Going back to 4.0.1 removes the ability to use the SwgohAPIFilter, but the relevant pieces don't work with that version either.

Going back to 3.2 removes the ToonImageRequestBuilder so I didn't test any further back than 4.0.0.

import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

import help.swgoh.api.SwgohAPI;
import help.swgoh.api.SwgohAPIBuilder;
import help.swgoh.api.SwgohAPIFilter;
import help.swgoh.api.image.ShipImageRequestBuilder;
import help.swgoh.api.image.ToonImageRequestBuilder;

public class Test {

  public static void main(String[] args) throws Exception {
    SwgohAPI api = new SwgohAPIBuilder()
        .withUsername( "daker13" )
        .withPassword( "************" )
        .build();

    try {
      System.out.println("First get some character info to prove I've got the api setup correctly");
      int allyCode = 421838524;
      Map<String, Object> matchCriteria = new HashMap<>();
      matchCriteria.put( "baseId", "GREEDO" );
      matchCriteria.put( "rarity", 7 );
      String greedoJson = api.getSupportData( SwgohAPI.Collection.unitsList,
          matchCriteria,
          SwgohAPI.Language.English,
          new SwgohAPIFilter( "nameKey", "combatType", "descKey", "thumbnailName", "baseId" )
      ).get();
      System.out.println(greedoJson);
    } catch(Exception e) {
      e.printStackTrace();
    }

    System.out.println("Now try the image api using the example at https://github.com/j0rdanit0/api-swgoh-help");
    //raw bytes of an image
    String baseId = "DARTHTRAYA"; //a full list of baseIds can be obtained through the "unitsList" collection
    try {
      byte[] bytes = api.getImage(
          new ToonImageRequestBuilder(baseId)
              .withStars(7)
              .withLevel(85)
              .withGear(12)
              .build()
      ).get();
    } catch(Exception e) {
      e.printStackTrace();
    }

    System.out.println("try with the buffered image too just to show both aren't working");
    //image in the form of a BufferedImage
    try {
      baseId = "TIEREAPER"; //a full list of baseIds can be obtained through the "unitsList" collection
      BufferedImage image = api.getBufferedImage(
          new ShipImageRequestBuilder(baseId)
              .withLevel(50)
              .withStars(5)
              .addPilot("DEATHTROOPER", 85, 11, 7, null)
              .addPilot("SHORETROOPER", 75, 5, 5, null)
              .build()
      ).get();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}

The output from running the above program is:

First get some character info to prove I've got the api setup correctly
[{"thumbnailName":"tex.charui_greedo","nameKey":"Greedo","combatType":1,"descKey":"Deadly Attacker that gains extra attacks from Critical Hits","baseId":"GREEDO"}]

Now try the image api using the example at https://github.com/j0rdanit0/api-swgoh-help
java.util.concurrent.ExecutionException: help.swgoh.api.exception.SwgohAPIException: Unable to complete request.
	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
	at Test.main(Test.java:45)
Caused by: help.swgoh.api.exception.SwgohAPIException: Unable to complete request.
	at help.swgoh.api.SwgohAPIClient.lambda$getImage$0(SwgohAPIClient.java:544)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
	at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.io.FileNotFoundException: https://api.swgoh.help/image/char/DARTHTRAYA?level=85&gear=12&rarity=7
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1890)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
	at java.net.URL.openStream(URL.java:1045)
	at help.swgoh.api.SwgohAPIClient.getImage(SwgohAPIClient.java:643)
	at help.swgoh.api.SwgohAPIClient.lambda$getImage$0(SwgohAPIClient.java:532)
	... 6 more
try with the buffered image too just to show both aren't working
java.util.concurrent.ExecutionException: help.swgoh.api.exception.SwgohAPIException: Unable to complete request.
	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
	at Test.main(Test.java:61)
Caused by: help.swgoh.api.exception.SwgohAPIException: Unable to complete request.
	at help.swgoh.api.SwgohAPIClient.lambda$getBufferedImage$1(SwgohAPIClient.java:570)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
	at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.io.FileNotFoundException: https://api.swgoh.help/image/ship/TIEREAPER?pilots=DEATHTROOPER-7-85-11-null%7CSHORETROOPER-5-75-5-null&level=50&rarity=5
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1890)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
	at java.net.URL.openStream(URL.java:1045)
	at help.swgoh.api.SwgohAPIClient.getBufferedImage(SwgohAPIClient.java:651)
	at help.swgoh.api.SwgohAPIClient.lambda$getBufferedImage$1(SwgohAPIClient.java:563)
	... 6 more

Process finished with exit code 0

If there is any additional data I can provide, please let me know.

Thanks,

Greg

@Minirogue
Copy link

I just asked about this on the Swgoh.help discord server. The image api has apparently been removed from the underlying api. So we're going to have to get these images some other way. This repo should probably be updated to remove ImageRequest or at least mark it as deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants