我在使用 gtm oauth 工具箱时遇到了发布问题。我一直在尝试向 Twitter 发送推文,但我不断收到授权错误。现在我收到以下错误,代码如下“POST 错误:错误域 = com.google.HTTPStatus 代码 = 401”操作无法完成。(com.google.HTTPStatus 错误 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"]);
}
}];
我在这里做错了什么?令牌已存储在钥匙串中。我需要检索钥匙串令牌还是 gtm 自动签署请求?