4

I'm trying to add fitbit integration into an iOS app. I'm surprised to find how difficult this is... I imagined there would be an iOS SDK.

In any case, I'm trying to pull the data via the web-based API. It uses OAuth 1 & 2.

I've tried both, but have made more progress with OAuth 2.0.

I'm currently using AFOAuth2Manager to connect. Unfortunately, it is not working well.

Using the demo code with my account info, I get the following error:

Request failed: unacceptable content-type: text/html

By adding:

OAuth2Manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

That error goes away, but a new one is presented:

JSON text did not start with array or object and option to allow fragments not set.

Here is the code I am using to make the request:

AFOAuth2Manager *OAuth2Manager =
        [[AFOAuth2Manager alloc] initWithBaseURL:baseURL
                                        clientID:@"CLIENT_ID"
                                          secret:@"CLIENT_SECRET"];

OAuth2Manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

[OAuth2Manager authenticateUsingOAuthWithURLString:@"/oauth2/authorize"
                                          username:USER_NAME
                                          password:USER_PASSWORD
                                             scope:@"activity"
                                           success: ^(AFOAuthCredential *credential) {
    NSLog(@"Token: %@", credential.accessToken);
}
                                           failure: ^(NSError *error) {
    NSLog(@"Error: %@", error);
}];

I wanted to try adding NSJSONReadingAllowFragments. But have been unable to get that into the code without error.

//OAuth2Manager.responseSerializer.readingOptions = NSJSONReadingAllowFragments;
5
  • Having the same problem at the moment.
    – kgaidis
    Jun 2, 2015 at 21:49
  • Could you please let me know, why and what are you using in USER_NAME and USER_PASSWORD?
    – Lion
    Sep 14, 2015 at 10:57
  • The below link has sample code with fitbit framework stackoverflow.com/questions/34393507/…
    – Karthik
    Dec 21, 2015 at 10:40
  • Did anyone found the solution for this as I am also having the same issue.
    – AmJa
    Jan 11, 2016 at 17:42
  • Go carefully through appengineer.in/2016/04/30/fitbit-aouth-in-ios-app . You will get step by step solution and source code for FitBit integration
    – Mahendra Y
    Apr 30, 2016 at 4:58

1 Answer 1

1

In my case, I appended the wrong path to the Base URL. For example, my path was "/oauth/access_token."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.