GTM OAuth Twitter update error 401

134 views
Skip to first unread message

Baxley

unread,
Jan 26, 2012, 11:13:48 PM1/26/12
to GTM OAuth 1 Discussion
I'm having a posting issue with the gtm oauth. 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?

Greg Robbins

unread,
Feb 8, 2012, 2:33:57 PM2/8/12
to gtm-...@googlegroups.com
The fetcher will use the authorizer to sign the request before sending it. The signed data may include the post body, depending on the body type.

Try turning on the fetcher's logging feature to see the server request and response. It's not practical to debug client/server code without looking at the http logs.


Reply all
Reply to author
Forward
0 new messages