对于任何Twitter API 请求,在 OSX Mavericks 10.9 上执行 Twitter 的 SLRequest 会返回“无法验证您”和错误代码 32 。简单的代码片段如下。
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
ACAccount *account = [accountsArray lastObject];
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1.1/help/test.json"];
SLRequest *r = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:nil];
r.account = account;
[r performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
dispatch_semaphore_signal(semaphore);
}];
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
令我感到奇怪的是,这个完全相同的代码片段在 iOS 上运行时没有任何问题。ACAccount 似乎有效,preparedURLRequest 似乎具有所有 OAuth HTTP 标头,我不确定可能有什么问题......有什么想法吗?