Reputation: 2991
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;
Upvotes: 4
Views: 1131
Reputation: 15609
In my case, I appended the wrong path to the Base URL. For example, my path was "/oauth/access_token."
Upvotes: 1