我正在尝试将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框架完成的。
我已阅读this reponse以及Twitter中的帖子。
有什么问题?
答案 0 :(得分:0)
如果令牌是OAToken,则应替换此
ACAccountCredential *credentials = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:token];
用这个
ACAccountCredential *outhCredential = [[ACAccountCredential alloc] initWithOAuthToken:token.key tokenSecret:token.secret];
你应该传递密钥&秘密作为第一和第二个论点。