2011-11-22 98 views
1

我在创建和保存iOS5上ACAccountStore的新Twitter帐户时遇到问题。在iOS5上创建twitter ACAccount时出错:NSURLErrorDomain错误-1012

执行完初始帐户的所有步骤后,ACAccountStore'ssaveAccount:withCompletionHandler:返回NSURLErrorDomain error -1012

有没有人有类似的问题?

我的代码示例如下使用requestToken来初始化ACAccountCrendential。此对象是一个OAToken(ShareKit对象),使用令牌和秘密在完成OAuth后收到的密码初始化。

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]); 
       } 
      }]; 
     } 
    }]; 

奇怪的是,苹果的Accounts Framework Reference表明saveAccount:withCompletionHandler:尝试执行OAuth本身:使用其凭据

如果帐户类型支持认证和帐户未通过身份验证,该帐户被认证 。如果认证成功,则保存帐户;否则,它不会被保存。

我觉得很奇怪,因为用户无法通过输入用户名/密码直接与服务器进行身份验证。

我也试图与我的应用程序的消费者密钥和消费者秘密进行初始化ACAccountCredential,具有相同的结果(与NSURLErrorDomain error -1012.失败)

有关这个主题的任何指导,将不胜感激!

谢谢。

回答

2

我在使用ACAccount添加Twitter帐户时遇到同样的问题。但是,我能够使用授权的OAuth访问令牌和访问令牌密钥成功创建带有ACAccount的Twitter帐户,而不是使用者密钥和使用者密钥。 (dev.twitter.com/apps->Twitter->OAuth->OAuth设置 - >访问令牌和访问令牌机密)这意味着您仍然必须使用OAuth库来获取授权的访问令牌和访问令牌时的秘密该用户正在添加一个Twitter帐户。

更新:您可以看到Twitter如何建议您将现有帐户迁移到iOS5系统帐户here。该链接为我提供了如何添加ACAccount的最佳示例。

相关问题