11-21-2014 11:40 - edited 11-21-2014 11:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-21-2014 11:40 - edited 11-21-2014 11:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi!
I want to write a simple application to download my own data. I've written the following code (in Ruby, but should be quite easily readalbe)
START CODE HERE
require 'rubygems'
require 'oauth';
:consumer_key = "Key received when registering my "app" with fitbit"
:consumer_secret = "Secret received when registering my "app" with fitbit"
consumer = OAuth::Consumer.new(
:consumer_key,
:consumer_secret,
{:site => 'https://api.fitbit.com'}
)
request_token = consumer.get_request_token
puts "Token:", request_token.token
puts "Secret: ", request_token.secret
puts "Auth URL", request_token.authorize_url
# At this stage once I get the auth URL, I type it in a browser and authorize my app. I get a verifier key and save it.
request_token = OAuth::RequestToken.new(consumer, :consumer_key, :consumer_secret)
access_token = request_token.get_access_token({:oauth_verifier => 'VERIFIED FROM WEBISTE GOES HERE'})
# At this stage, I get a 401 Auth failed error.
END CODE
Questions:
- What am I doing wrong?
- Once I get the auth going? How can I do subsequent calls without having to authorize the app in the browser every time I want data?
Thanks!

- Labels:
-
Subscriptions API
11-21-2014 18:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-21-2014 18:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
The error should also say a reason why it failed.
Please post here more details what the error response is.
Senior Software Developer at Fitbit

11-21-2014 23:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-21-2014 23:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Does this help? This is the output from Rubymine.
/Library/Ruby/Gems/2.0.0/gems/oauth-0.4.7/lib/oauth/consumer.rb:216:in `token_request': 401 Unauthorized (OAuth::Unauthorized)
from /Library/Ruby/Gems/2.0.0/gems/oauth-0.4.7/lib/oauth/tokens/request_token.rb:18:in `get_access_token'
from /Users/rahulm/RubymineProjects/Fit/Fitbit.rb:26:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
Process finished with exit code 1

11-22-2014 00:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-22-2014 00:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It is hard to say from provided information what API requests rae you making.
Please check out Fitbit Oauth 1.0a debug page it has informatino on what exact requests your app should be making to get access token.
Also please check out https://wiki.fitbit.com/display/API/OAuth+Authentication+in+the+Fitbit+API for more details.
Senior Software Developer at Fitbit

11-22-2014 00:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-22-2014 00:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks for the reply. My code is exactly what I posted in my first post (except, I removed the actualy key and secret). I'm curious what I'm missing in my code thats causing me to get the errors.

11-23-2014 10:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-23-2014 10:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I got the code working. However when I try the following I get an error:
I was able to scucessfully get past the previous auth errors.
@activity_sample = access_token.get('/1/user/-/activities/date/2014-02-25.json'): I get ghost user! Error!
@activity_sample = access_token.get('/1/user/@account_email_id/activities/date/2014-02-25.json'): I get page not found.
What am I doing wrong now? Do I need to provide more headers I'm not?

11-23-2014 10:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-23-2014 10:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Ah! Never mind! I figured it out! Am able to get responses now! Thanks!

