Skip to content
This repository

Add Fitbit API Support #269

Closed
wants to merge 1 commit into from

4 participants

Alexander Pakulov Eric Jain Vadim Zaliva Pablo Fernandez
Alexander Pakulov

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

Eric Jain

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

Pablo Fernandez fernandezpablo85 closed this February 27, 2013
Vadim Zaliva

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

Showing 1 unique commit by 1 author.

May 16, 2012
Alexander Pakulov Fitbit API Support b9fe95d
This page is out of date. Refresh to see the latest.
22  src/main/java/org/scribe/builder/api/FitbitApi.java
... ...
@@ -0,0 +1,22 @@
  1
+package org.scribe.builder.api;
  2
+
  3
+import org.scribe.model.Token;
  4
+
  5
+public class FitbitApi extends DefaultApi10a {
  6
+    private static final String AUTHORIZATION_URL = "http://www.fitbit.com/oauth/authorize?oauth_token=%s";
  7
+
  8
+    @Override
  9
+    public String getRequestTokenEndpoint() {
  10
+        return "http://api.fitbit.com/oauth/request_token";
  11
+    }
  12
+
  13
+    @Override
  14
+    public String getAccessTokenEndpoint() {
  15
+        return "http://api.fitbit.com/oauth/access_token";
  16
+    }
  17
+
  18
+    @Override
  19
+    public String getAuthorizationUrl(Token requestToken) {
  20
+        return String.format(AUTHORIZATION_URL, requestToken.getToken());
  21
+    }
  22
+}
56  src/test/java/org/scribe/examples/FitbitExample.java
... ...
@@ -0,0 +1,56 @@
  1
+package org.scribe.examples;
  2
+
  3
+import org.scribe.builder.ServiceBuilder;
  4
+import org.scribe.builder.api.FitbitApi;
  5
+import org.scribe.model.*;
  6
+import org.scribe.oauth.OAuthService;
  7
+
  8
+import java.util.Scanner;
  9
+
  10
+public class FitbitExample {
  11
+    private static final String PROTECTED_RESOURCE_URL = "http://api.fitbit.com/1/user/-/profile.json";
  12
+
  13
+    public static void main(String[] args) {
  14
+        // Replace these with your own api key and secret
  15
+        String apiKey = "consumer_key";
  16
+        String apiSecret = "consumer_secret";
  17
+
  18
+        OAuthService service = new ServiceBuilder().provider(FitbitApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
  19
+        Scanner in = new Scanner(System.in);
  20
+
  21
+        System.out.println("=== Fitbit's OAuth Workflow ===");
  22
+        System.out.println();
  23
+
  24
+        // Obtain the Request Token
  25
+        System.out.println("Fetching the Request Token...");
  26
+        Token requestToken = service.getRequestToken();
  27
+        System.out.println("Got the Request Token!");
  28
+        System.out.println();
  29
+
  30
+        System.out.println("Now go and authorize Scribe here:");
  31
+        System.out.println(service.getAuthorizationUrl(requestToken));
  32
+        System.out.println("And paste the verifier here");
  33
+        System.out.print(">>");
  34
+        Verifier verifier = new Verifier(in.nextLine());
  35
+        System.out.println();
  36
+
  37
+        // Trade the Request Token and Verfier for the Access Token
  38
+        System.out.println("Trading the Request Token for an Access Token...");
  39
+        Token accessToken = service.getAccessToken(requestToken, verifier);
  40
+        System.out.println("Got the Access Token!");
  41
+        System.out.println("(if your curious it looks like this: " + accessToken + " )");
  42
+        System.out.println();
  43
+
  44
+        // Now let's go and ask for a protected resource!
  45
+        System.out.println("Now we're going to access a protected resource...");
  46
+        OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  47
+        service.signRequest(accessToken, request);
  48
+        Response response = request.send();
  49
+        System.out.println("Got it! Lets see what we found...");
  50
+        System.out.println();
  51
+        System.out.println(response.getBody());
  52
+
  53
+        System.out.println();
  54
+        System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
  55
+    }
  56
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.