I'm having a posting issue with the gtm oauth toolbox. I've been trying to send a tweet to twitter but I keep getting authorization errors. Right now I'm receiving the following error with the code below "POST error: Error Domain=com.google.HTTPStatus Code=401 "The operation couldn’t be completed. (com.google.HTTPStatus error 401.)"
NSString *body = [NSString stringWithFormat: @"status=thisisatest"];
NSString *urlStr = @"http://api.twitter.com/1/statuses/update.json";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]];
GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher
fetcherWithRequest:request];
[myFetcher setAuthorizer: mAuth];
[myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData,
NSError *error)
{
if (error != nil)
{
NSLog(@"POST error: %@", error);
}
else
{
NSDictionary *results = [[[[NSString alloc] initWithData:
retrievedData encoding:NSUTF8StringEncoding] autorelease] JSONValue];
NSLog(@"POST Successful: #%@ @ %@", [results objectForKey:
@"id"], [results objectForKey: @"created_at"]);
}
}];
What am I doing wrong here? The token is already stored in the keychain. Do I need to retrieve the keychain token or does gtm sign the request automatically?
Ok, I found out the issue. I missed a place in one of the GTM .m files for the consumer key. That's what I get for rushing things. :-)