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

I cannot log the water

After getting the access token i cannot log the waterusing post method while the get water log method is working perfectly. That always return the error {"errors":[{"errorType":"validation","fieldName":"amount","message":"Amount is required"}]}.
But the Parameter amount is ok。The code such as:

NSString *str= @"https://api.fitbit.com/1/user/-/foods/log/water.json";
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"170.0",@"amount",@"2015-07-07",@"date",nil];
NSString *oAuthValue = [_oAuthFitBit oAuthHeaderForMethod:@"POST" andUrl:str andParams:params]
NSURL *url = [NSURL URLWithString:str];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[httpClient setDefaultHeader:@"Authorization" value:oAuthValue];

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
path:[url path]
parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

NSError *err = nil;
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&err];
NSLog(@"%@ fitbit response=%@",@"fitbit ",responseDict);
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"error messages getting %@",error);

}];
[operation start];

Any help will be appreciated,Thanks!

Best Answer
0 Votes
0 REPLIES 0