THE OBJECTIVE

The objective is to find a technical way to implement a fitness tracking solution using Java technologies and an existing API available on the public web. The main functionality is recording an object’s moves.

To use the service, you install a mobile application provided by a third-party service, which records all the moves and sends them to the remote service.

EXISTING SOLUTIONS FOR TRACKING

During the investigation of tracking solutions available on the public Internet we found the following services:

  • Fitbit;
  • Misfit;
  • Moves App.

Many of them offer developer APIs, so you can work with their data in your own applications, products and services.

Almost all services use OAuth as an authorization method.

FITBIT

Fitbit helps to deliver results

Fitbit helps to deliver results

The Fitbit service uses OAuth 2.0 for authorization. This service provides API services for receiving a summary of activities, tracks and the activity log.

These services have their own proprietary implementations as seen from descriptions.

MISFIT

Java saves the time

Java saves the time

Misfit also uses OAuth 2.0. It provides API services for user applications, and they return information similar to Fitbit’s.

MOVES APP

Moves App is one of the tracking technologies available in the market

Moves App is one of the tracking technologies available in the market

The Moves App service uses the OAuth 2.0 standard for authentication.

It provides API services for receiving a summary of activities, tracks and the activity log.

We will take advantage of this API and interact with Moves App to record moves and get the latest positions and history; then we will display the latest position and the history in a user-friendly manner.

The intention of this effort is to demonstrate the use of Java technology for this purpose, within the continuous integration (CI) environment.

Moves App platform is well suited for collecting data of human movement activities and is a platform designed for everyday use. It deploys a mobile application that collects the information about users’ moves, transportation and other activities, and stores the history of all users’ activities. The history is available upon request using the provided API.

It provides the mobile application which takes advantage of this.

DOMAIN OF OUR APPLICATION

The domain of the application is fitness movement tracking using the Moves App and interface.

WHAT ENVIRONMENT DO WE HAVE?

In this project we use Git for version control and Jenkins as the CI build system, as it has proven itself a stable and mature build service.

LET’S START – CREATE AN APPLICATION

We will show how simply we can get our new Java application done using this infrastructure.

Let’s choose the name: “SampleMovesApp”

Step 1.

In order to use Moves App API services, it is important to register your application on the website of Moves App. This is done on the Moves App website, in the Connected Apps section.

The Moves App page for your applications:

Create a new app

Then you add your application. When you add it, you are issued your client ID (clientId) and your private secret key (clientSecret); this information is to be used during the authentication with the Moves App service.

After successful authorization with the Moves App, your application gets a grant code.

Step 2.

Download moves-java, an open-source Java client for the Moves API that already has all the interfaces you need.

Step 3.

Using Maven, we create the project and add the dependencies: the first one is for authorization, the second is for working with Moves, and the last two are for tests.

<dependency>  
     <groupId>org.apache.oltu.oauth2</groupId> 
     <artifactId>org.apache.oltu.oauth2.client</artifactId> 
     <version>1.0.1</version> 
</dependency>  
<dependency>  
     <groupId>me.pims.moves</groupId> 
     <artifactId>moves-java</artifactId> 
     <version>0.1</version> 
</dependency>  
<dependency>  
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
</dependency>  
<dependency>  
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-all</artifactId> 
     <version>1.10.19</version> 
</dependency>

Step 4.

Moves App uses OAuth2 for authorization. Before we can use OAuth2, we need to receive a Grant Code from Moves App by sending a request to the Moves App API endpoint with your client ID and client secret. In response, you will receive the grant code. After you receive your grant code, it is possible to use OAuth2 to request an access token. You must have a valid access token before you can use the API (the diagram below shows how to obtain one).

Authentication: receiving a Grant Code from Moves App

Then we create a connector with all the important business methods for getting the necessary summary data.

public void start() {  
     assert !isStarted() : "Already started" 
     String token = getToken(); 
     this.moves = new MovesBuilder().setToken(token).build(); 
} 

public void startWithMock(Moves movesMock) {  
     assert !isStarted() : "Already started"; 
     this.moves = movesMock; 
} 

public List<Summary> getSummary(String fromTime, String toTime) {  
     assert isStarted() : "Not started"; 
     return moves.summary(fromTime, toTime); 
} 

private String getToken() {  
    assert code != null : "Code not set"; 
    if (token == null) { 
        try { 
            OAuthClientRequest request = OAuthClientRequest 
                    .tokenLocation("https://api.moves-app.com/oauth/v1/access_token") 
                    .setGrantType(GrantType.AUTHORIZATION_CODE) 
                    .setCode(code) 
                    .setClientId(clientId) 
                    .setClientSecret(clientSecret) 
                    .buildQueryMessage(); 
            OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); 
            token = oAuthClient.accessToken(request).getAccessToken(); 
            log.info("Access token: " + token); 
        } catch (OAuthSystemException e) { 
            log.error("System error authorizing using oauth", e); 
        } catch (OAuthProblemException e) { 
            log.error("Problem authorizing using oauth", e); 
        } 
    } 
    return token; 
}

Step 5.

Let’s cover the code with unit tests. Below is an example that keeps the work error-free:

@Test 
public void testSummary() {  
     when(connector.getSummary(new Date())).thenReturn(new ArrayList<Summary>()); 
     when(connector.getSummary(new Date(), new Date())).thenReturn(new ArrayList<Summary>()); 
     when(connector.getSummary("", "")).thenReturn(new ArrayList<Summary>()); 
     when(connector.getSummary("")).thenReturn(new ArrayList<Summary>()); 
     when(moves.summary("")).thenReturn(new ArrayList<Summary>()); 
     when(moves.summary("", "")).thenReturn(new ArrayList<Summary>()); 
     connector.getSummary("", ""); 
     verify(moves, times(1)).summary("", ""); 
}

Step 6.

@GET 
@Path("/weekly/summary") 
@Produces(MediaType.APPLICATION_JSON) 
public String weeklySummary(@Context ServletRequest request) {  
     Calendar calTo = Calendar.getInstance(TimeZone.getTimeZone("GMT")); 
     Calendar calFrom = Calendar.getInstance(TimeZone.getTimeZone("GMT")); 
     calFrom.add(Calendar.WEEK_OF_MONTH, -1); 
     return summariesToJson(MovesAppSingleton.getInstance().getConnector().getSummary(calFrom.getTime(), calTo.getTime())); 
}

Step 7.

As the last step, we create a Sencha Ext JS web table that shows the Moves summary:

Ext.define('Activity',{  
     extend: 'Ext.data.Model', 
     fields: [ 
         'date', 'name', 'duration', 'steps', 'distance' 
     ] 
}); 

var store = Ext.create('Ext.data.Store', {  
     model: 'Activity', 
     autoLoad: true, 
     proxy: { 
         type: 'ajax', 
         url: '/ihealth/rest/moves/weekly/summary', 
         reader: { 
             type: 'json', 
             rootProperty: 'items' 
         } 
     } 
}); 

var grid = Ext.create('Ext.grid.Panel', {  
     store: store, 
     columns: [ 
         {text: "Date", width:120, dataIndex: 'date'}, 
         {text: "Name", width:120, dataIndex: 'name'}, 
         {text: "Duration, s", width: 120, dataIndex: 'duration'}, 
         {text: "Steps", width: 120, dataIndex: 'steps'}, 
         {text: "Distance, m", width: 120, dataIndex: 'distance'} 
     ], 
     forceFit: true, 
     height: '400', 
     split: true, 
     region: 'north' 
});

Let’s check CI status:

Five out of five our java Unit Tests are done great

Five out of five our java Unit Tests are done great.

The most pleasant thing is that when we commit a change to our Git repository, the infrastructure builds the application and deploys that to our application server automatically and we can see the result:

History received in live mode from the Moves App using the API provided by the Moves App

Any Java developer can implement an application like this in a few hours when the development infrastructure is well organized.

CONCLUSION

A tracking service can be built on the APIs available on the market. With a correctly configured software development infrastructure, CI environment and management tools, it is easier to coordinate development, keep the work transparent, manage changes and deliver the solution on time.

Any company with Java developers, or any Java developer, can use our examples to see how it works.

Update (November 2026): Facebook shut down the Moves app and the Moves API on 31 July 2018, so the endpoints in this example no longer respond, and Apache Oltu, the OAuth client from Step 3, was retired to the Apache Attic the same year. Fossil shut down Misfit’s app and cloud API in 2023, and Google is turning off the Fitbit Web API on 2 November 2026 in favour of the Google Health API. The code above stays as a record of how the integration was built in 2016.