【发布时间】:2013-11-30 17:23:23
【问题描述】:
在 OSX Mavericks 10.9 上执行 Twitter 的 SLRequest 会返回“无法对您进行身份验证”以及 任何 Twitter API 请求的错误代码 32。简单代码sn-p如下。
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);
让我感到奇怪的是,这个完全相同代码 sn-p 在 iOS 上运行没有任何问题。 ACAccount 似乎有效,preparedURLRequest 似乎具有所有 OAuth HTTP 标头,我不确定可能有什么问题......有什么想法吗?
【问题讨论】:
标签: objective-c macos twitter osx-mavericks slrequest