1

I work on ios application that use Google fusion tables. in previous question I got advice and made progress but still struggle with creating fusion table. my code:

NSString *url = @"https://www.googleapis.com/fusiontables/v1/tables";

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myTableDict options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonDataString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSData *postData = [jsonDataString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
GTMHTTPFetcher *fetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[fetcher setAuthorizer:self.auth];
[fetcher setPostData:postData];
void(^createHandler)(NSData *data, NSError *error) = ^(NSData *data, NSError *error){
    if (error) {
        NSLog(@"error creating table %@", [error localizedDescription]);
    }
};
[fetcher beginFetchWithCompletionHandler:createHandler];

But I am getting error: "The operation couldn’t be completed. (com.google.HTTPStatus error 400.)". what am I doing wrong?

1 Answer 1

1

looks like a good progress. in your code you seem to be missing setting the http header content type, should be:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
GTMHTTPFetcher *fetcher = [GTMHTTPFetcher fetcherWithRequest:request];

also, when doing GTMHTTPFetcher error processing you might get more info using:

NSData *data = [[error userInfo] valueForKey:@"data"];
NSString *errorDataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
0

Your Answer

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

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