title: Fitbit and OAuth 2.0
body: <p>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. </p>
  
  <p>In any case, I'm trying to pull the data via the web-based API. It uses OAuth 1 &amp; 2. </p>
  
  <p>I've tried both, but have made more progress with OAuth 2.0. </p>
  
  <p>I'm currently using <strong>AFOAuth2Manager</strong> to connect. Unfortunately, it is not working well. </p>
  
  <p>Using the demo code with my account info, I get the following error: </p>
  
  <blockquote>
    <p>Request failed: unacceptable content-type: text/html</p>
  </blockquote>
  
  <p>By adding:</p>
  
  <pre><code>OAuth2Manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
  </code></pre>
  
  <p>That error goes away, but a new one is presented: </p>
  
  <blockquote>
    <p>JSON text did not start with array or object and option to allow
    fragments not set.</p>
  </blockquote>
  
  <p>Here is the code I am using to make the request: </p>
  
  <pre><code>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);
  }];
  </code></pre>
  
  <p>I wanted to try adding NSJSONReadingAllowFragments. But have been unable to get that into the code without error. </p>
  
  <pre><code>//OAuth2Manager.responseSerializer.readingOptions = NSJSONReadingAllowFragments;
  </code></pre>