我正在尝试将 Twitter 帐户保存到ACAccountStore
.
我正在对用户进行身份验证MPOauth
(这非常有效,我可以进行身份验证并发布消息),当我收到访问令牌和访问令牌秘密时,我会继续保存帐户。
首先,我将令牌访问拆分为只获取令牌本身,而不是用户 ID。之后这是我的代码
if ([username length] > 0 && [token length] > 0 && [secret length] > 0) {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAccount *account = [[ACAccount alloc] initWithAccountType:accountType];
ACAccountCredential *credentials = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
[account setCredential:credentials];
[account setUsername:username];
[accountStore saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"the account was saved!");
} else {
NSLog(@"the account was NOT saved");
}
[accountStore release];
[account release];
[credentials release];
}];
}
但从来没有工作,我明白了
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)"
我读到这响应了针对 Twitter 验证数据的错误,这是由 iOS5 框架在保存帐户之前完成的。
怎么了?