How to connect to an Api with username and application key

edited November 2017 in Library Questions

Hello all.

As part of a new project I would like to connect to an external api with a username and application key. I understand how to connect to a simple api and load/get the JSON data but after much searching I can't find details on how to login to an API prior to connecting and retrieving data.

Is this doable from within a processing sketch?

I have the endpoint URL but can't practice extracting the data through processing as I can't apply my credentials that way.

If anyone could point me in the right direction it would be greatly appreciated.

Cheers

Answers

  • edited November 2017

    I made this a while back for Wolfram's API. See if you can change it to get it work for you :

    import java.net.*;
    
    String Query = "http://" + "api.wolframalpha.com/v2/query?input=derivative+of+x%5E4&appid=#########";
    String[] results;
    
    void setup() {
      try {
        URL url = new URL(Query);
        URLConnection connection = url.openConnection();
        results = loadStrings(connection.getInputStream());
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      printArray(results);
    }
    
  • Many thanks. Will have a play with it and see what happens.

Sign In or Register to comment.