【问题标题】:Error creating twitter ACAccount on iOS5: NSURLErrorDomain error -1012在 iOS5 上创建 twitter ACAccount 时出错:NSURLErrorDomain 错误 -1012
【发布时间】: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


    【解决方案1】:

    我在使用 ACAccount 添加 Twitter 帐户时遇到了同样的问题。但是,我能够使用授权的 OAuth 访问令牌和访问令牌秘密,而不是消费者密钥和消费者秘密,成功地创建了一个带有 ACAccount 的 Twitter 帐户。 (dev.twitter.com/apps->Twitter->OAuth->OAuth Setting-->Access token and Access token secret) 这意味着你仍然需要使用 OAuth 库来获取授权的 Access token 和 Access token secret用户正在添加 Twitter 帐户。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多