How to Temboo with Java

Temboo makes it easy to build Java applications that connect to over 100 web-based resources and services (e.g. Facebook, Dropbox, US Census data) by standardizing how you interact with their Application Programming Interfaces (APIs). Don't worry if you're not familiar with APIs – with Temboo you don't have to worry about the details.

Here we'll show you how to use the Temboo Java SDK to write a simple Java class that uses Google's Geocoding API to retrieve the latitude and longitude for a specific address. What makes Temboo uniquely powerful and useful is that, once you know how to use one API, you know how to work with any API in our Library.

Before we get started, make sure that you've got Java 1.6 (or later) and a Java code editor. We've used Eclipse for these tutorials, but they will work equally well in whatever IDE you are using.

Get Set up

1 Create a new Java project in Eclipse and add a folder called "/libs".

2Download the Temboo Java SDK.

3 Copy the downloaded JAR into the "/libs" folder. Refresh the project, then right-click the JAR file and select:
Build Path > Add to Build Path.

4 Add a new Java class containing a main method to your project. You can call it whatever you like.

Test on our website

5 Log in to Temboo. If you don't already have an account, you can register for free here.

6 Go to the Google > Geocoding > GeocodeByAddress Choreo in our Library. Select Java from the drop down menu at the top of the page.

7 Enter any address or ZIP code in the Address input field e.g., 104 Franklin Street, New York City.

8 Now click Generate Code to test the Choreo from our website. After a moment you'll see the data that Google sends back shown in the Output section.

Auto-Generate The Code

When you run any Choreo from our website, we automatically generate code that can be used to make the same API call in many languages, including Java. Here we'll show you how to use these snippets in your code.

9 Scroll down to find the Code section of the Library page.

10 Copy the code snippet and paste it into the main method of your Java class. Press Cmd+Shift+O (or Ctrl+Shift+O in Windows) to automatically import dependencies. Note: your main method should declare that it throws Exception.

At this point, your code should look something like this:

import com.temboo.Library.Google.Geocoding.GeocodeByAddress;
import com.temboo.Library.Google.Geocoding.GeocodeByAddress.GeocodeByAddressInputSet;
import com.temboo.Library.Google.Geocoding.GeocodeByAddress.GeocodeByAddressResultSet;
import com.temboo.core.TembooSession;

public class HelloTemboo {

  public static void main(String[] args) throws Exception {

    // Instantiate the choreography, using a previously instantiated TembooSession object, eg:
    TembooSession session = new TembooSession("ACCOUNT_NAME", "APP_NAME", "APP_KEY");
    GeocodeByAddress geocodeByAddressChoreo = new GeocodeByAddress(session);

    // Get an InputSet object for the choreo
    GeocodeByAddressInputSet geocodeByAddressInputs = geocodeByAddressChoreo.newInputSet();

    // Set inputs
    geocodeByAddressInputs.set_Address("104 Franklin St., New York NY 10013");

    // Execute choreography
    GeocodeByAddressResultSet geocodeByAddressResults = geocodeByAddressChoreo.execute(geocodeByAddressInputs);

11Import dependencies again, making sure to select the Temboo packages.

Print results

Before we try a test run of the app, let's update the code to print the results returned from Google's Geocoding service.

Each Choreo in the Java SDK returns a ResultSet subclass that contains get methods tailored specifically to the outputs of that Choreo. Using the ResultSet, you can retrieve the raw data (typically XML or JSON) returned by a third-party API or relevant fields that we've parsed out of the response for you.

To print the latitude and longitude returned by the Choreo, simply do the following:

12 Add the following code at the bottom of the main method in your class:

// Print lat and lon
System.out.println("Latitude: " + geocodeByAddressResults.get_Latitude());
System.out.println("Longitude: " + geocodeByAddressResults.get_Longitude());

Try It Out

13 Run the code and you will see the results in the console. Congrats! You just ran your first Choreo from our Java SDK.

What next?

Now you're ready to run any of our 2000+ Choreos in Java. You're just a few steps away from making something extraordinary. You can check out some more examples that use our Java SDK here.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.

Need help?

We're always happy to help. Just email us at, and we'll answer your questions.