Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API Authentication question

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! 

Best Answer
0 Votes
6 REPLIES 6

The error should also say a reason why it failed.

Please post here more details what the error response is.

Ivan Bahdanau
Senior Software Developer at Fitbit
Best Answer
0 Votes

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

Best Answer
0 Votes

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.

Ivan Bahdanau
Senior Software Developer at Fitbit
Best Answer
0 Votes

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. 

Best Answer
0 Votes

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? 

 

Best Answer
0 Votes

Ah! Never mind! I figured it out! Am able to get responses now! Thanks! 

Best Answer
0 Votes