【发布时间】:2012-01-03 17:17:46
【问题描述】:
我在 iOS5 上创建新 Twitter 帐户并将其保存到 ACAccountStore 时遇到问题。
在执行完所有初始化帐户的步骤后,ACAccountStore'ssaveAccount:withCompletionHandler: 返回NSURLErrorDomain error -1012。
有人有类似的问题吗?
我下面的代码示例是使用 requestToken 来初始化 ACAccountCrendential。该对象是一个OAToken(ShareKit 对象),在完成OAuth 后使用从twitter 收到的令牌和秘密进行初始化。
ACAccountStore *store = [[[ACAccountStore alloc] init] autorelease];
ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAccount *account = [[[ACAccount alloc] initWithAccountType:twitterAccountType] autorelease];
account.username = @"twitterusername";
account.credential = [[[ACAccountCredential alloc] initWithOAuthToken:requestToken.key tokenSecret:requestToken.secret] autorelease];
[store requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted) {
[store saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"TWITTER ACCOUNT CREATED SUCCESSFULLY!");
}
else{
NSLog(@"ERROR creating twitter account: %@", [error description]);
}
}];
}
}];
奇怪的是,Apple 的 Accounts Framework Reference 暗示 saveAccount:withCompletionHandler: 尝试执行 OAuth 本身:
如果账户类型支持认证且账户未认证,则账户认证 使用其凭据。如果认证成功,则保存账号;否则不保存。
我觉得这很奇怪,因为用户无法通过输入用户名/密码直接与服务器进行身份验证。
我还尝试使用我的应用程序的消费者密钥和消费者密钥初始化 ACAccountCredential,结果相同(以 NSURLErrorDomain error -1012. 失败)
我们将不胜感激任何有关此主题的指导!
谢谢。
【问题讨论】:
标签: iphone twitter ios5 accounts