Question

I am trying make a call to the fitbit API. I am unsure how to input the HTTP request shown below into my Objective C code in order to make this call and handle the response.

POST /oauth/request_token HTTP/1.1
Host: api.fitbit.com
Authorization: OAuth oauth_consumer_key="fitbit-example-client-application",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1270248082",
oauth_nonce="161822064",
oauth_callback="http%3A%2F%2Fexample.fitbit.com%2Fapp%2FcompleteAuthorization",
oauth_signature="Omf%2Bls2gn%2BDlghq245LRIyfMdd8%3D"
oauth_version="1.0"

A simple example would be helpful. Thank you.

Was it helpful?

Solution

I suggest using an OAuth library to handle the OAuth signature generation. It can be a pain in the ass to wrangle the Authorization header. I've used oauthconsumer with success.

Code sample:

OAConsumer *consumer = [[OAConsumer alloc] initWithKey:oauthConsumerKey secret:oauthConsumerSecret];
OAToken *token = [[OAToken alloc] initWithKey:oauthAccessToken secret:oauthAccessTokenSecret];
OAHMAC_SHA1SignatureProvider *provider = [[OAHMAC_SHA1SignatureProvider alloc] init];

OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString] consumer:consumer token:token realm:nil signatureProvider:provider];
[request prepare];

NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

In this example, the 5 strings you will provide are:

oauthConsumerKey
oauthConsumerSecret
oauthAccessToken
oauthAccessTokenSecret
urlString

OTHER TIPS

I am trying to do the same thing and oauthconsumer looks quite nice.

Is it because I am not getting the oauthAccessTokenSecret? [edit] Yes, it was.

I keep getting: "This page is no longer valid. It looks like you provided an invalid token or someone already used the token you provided. Please return to the site or application which sent you to this page and try again."

[edit] This is because it didn't have the correct token on the url string.

Hi you can get the working FitBit Oauth1.0 Authentication sample code from below link

https://github.com/KaranRajpoot/FitBit

Use OAuth.io, and the OAuth.io iOS SDK, to connect to FitBit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top