Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Fitbit API Support #269

Closed
wants to merge 1 commit into from

4 participants

@apakulov

Hi Pablo, I've added the Fitbit OAuth 1.0 API Adapter with example ( https://wiki.fitbit.com/display/API )

@ejain

How about replacing http with https? Fitbit currently supports both, but may deprecate http.

@vzaliva

Any reason why this has not been added to main repo? I tested and the code works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 16, 2012
  1. @apakulov

    Fitbit API Support

    apakulov authored
This page is out of date. Refresh to see the latest.
View
22 src/main/java/org/scribe/builder/api/FitbitApi.java
@@ -0,0 +1,22 @@
+package org.scribe.builder.api;
+
+import org.scribe.model.Token;
+
+public class FitbitApi extends DefaultApi10a {
+ private static final String AUTHORIZATION_URL = "http://www.fitbit.com/oauth/authorize?oauth_token=%s";
+
+ @Override
+ public String getRequestTokenEndpoint() {
+ return "http://api.fitbit.com/oauth/request_token";
+ }
+
+ @Override
+ public String getAccessTokenEndpoint() {
+ return "http://api.fitbit.com/oauth/access_token";
+ }
+
+ @Override
+ public String getAuthorizationUrl(Token requestToken) {
+ return String.format(AUTHORIZATION_URL, requestToken.getToken());
+ }
+}
View
56 src/test/java/org/scribe/examples/FitbitExample.java
@@ -0,0 +1,56 @@
+package org.scribe.examples;
+
+import org.scribe.builder.ServiceBuilder;
+import org.scribe.builder.api.FitbitApi;
+import org.scribe.model.*;
+import org.scribe.oauth.OAuthService;
+
+import java.util.Scanner;
+
+public class FitbitExample {
+ private static final String PROTECTED_RESOURCE_URL = "http://api.fitbit.com/1/user/-/profile.json";
+
+ public static void main(String[] args) {
+ // Replace these with your own api key and secret
+ String apiKey = "consumer_key";
+ String apiSecret = "consumer_secret";
+
+ OAuthService service = new ServiceBuilder().provider(FitbitApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
+ Scanner in = new Scanner(System.in);
+
+ System.out.println("=== Fitbit's OAuth Workflow ===");
+ System.out.println();
+
+ // Obtain the Request Token
+ System.out.println("Fetching the Request Token...");
+ Token requestToken = service.getRequestToken();
+ System.out.println("Got the Request Token!");
+ System.out.println();
+
+ System.out.println("Now go and authorize Scribe here:");
+ System.out.println(service.getAuthorizationUrl(requestToken));
+ System.out.println("And paste the verifier here");
+ System.out.print(">>");
+ Verifier verifier = new Verifier(in.nextLine());
+ System.out.println();
+
+ // Trade the Request Token and Verfier for the Access Token
+ System.out.println("Trading the Request Token for an Access Token...");
+ Token accessToken = service.getAccessToken(requestToken, verifier);
+ System.out.println("Got the Access Token!");
+ System.out.println("(if your curious it looks like this: " + accessToken + " )");
+ System.out.println();
+
+ // Now let's go and ask for a protected resource!
+ System.out.println("Now we're going to access a protected resource...");
+ OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
+ service.signRequest(accessToken, request);
+ Response response = request.send();
+ System.out.println("Got it! Lets see what we found...");
+ System.out.println();
+ System.out.println(response.getBody());
+
+ System.out.println();
+ System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
+ }
+}
Something went wrong with that request. Please try again.