我在试着把推特账户存到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框架在保存帐户之前所做的事情。
我已经在Twitter上读过this reponse和这篇文章了。
怎么啦?
发布于 2012-08-24 15:49:03
如果token为OAToken,则应替换
ACAccountCredential *credentials = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:token];有了这个
ACAccountCredential *outhCredential = [[ACAccountCredential alloc] initWithOAuthToken:token.key tokenSecret:token.secret];您应该分别将key和secret作为第一个和第二个参数进行传递。
https://stackoverflow.com/questions/12104976
复制相似问题