Fetching from API. Please Help me

Hi all, I wanted to know how to fetch data from an API in java. Can some one please help me doing this work.

Thank you. :smile:

1 Like

see the web component in the MIT App Inventor sources

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

3 Likes

Where does the API come from?

Use httpurlconnection to do get and post requests

https://api.wheretheiss.at/v1/satellites/25544

I have looked there but I am not getting any idea :grin:

  @SimpleFunction
  public void Get() {
final String METHOD = "Get";
// Capture property values in local variables before running asynchronously.
final CapturedProperties webProps = capturePropertyValues(METHOD);
if (webProps == null) {
  // capturePropertyValues has already called form.dispatchErrorOccurredEvent
  return;
}

AsynchUtil.runAsynchronously(new Runnable() {
  @Override
  public void run() {
    performRequest(webProps, null, null, "GET", METHOD);
  }
});
  }

  /**
   * Performs an HTTP POST request using the Url property and the specified text.
   *
   *   The characters of the text are encoded using UTF-8 encoding.
   *
   *   If the SaveResponse property is true, the response will be saved in a
   * file and the GotFile event will be triggered. The responseFileName property
   * can be used to specify the name of the file.
   *
   *   If the SaveResponse property is false, the GotText event will be triggered.
   *
   * @param text the text data for the POST request
   */

This is the code I have got from MIT App Inventor Sources

what do you want to take from the ISS?
Json File?

Yes!! I want JSON

1 Like

from this link?
https://api.wheretheiss.at/v1/satellites/25544

after getting the json text do you want to change it to plain text or keep json?

Yes. I want the JSON from that link

I have done it :sunglasses: :star_struck:

Can you please show... :face_with_monocle: :hugs:

1 Like

So..... :grin:

Okay :grin:

Do you want me to give the extension first so you can see how it works or the source code

Yes, very very sure.....

extension?
or source code?

Source code is needed. You don't waste time compiling extension... :grin:

Hi @Alpha2020
You should check this:

Okay, please try it, I have tried it and my code was successful 100%

com.extension.issinfo.aix (6.1 KB)

IssInfo.txt (2.2 KB)

1 Like