在iOS5上创建twitter ACAccount时出错:NSURLErrorDomain错误-1012 [英] Error creating twitter ACAccount on iOS5: NSURLErrorDomain error -1012

查看:419
本文介绍了在iOS5上创建twitter ACAccount时出错:NSURLErrorDomain错误-1012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS5上创建并将新的Twitter帐户保存到 ACAccountStore 时遇到问题。

I am having trouble creating and saving a new twitter account to ACAccountStore on iOS5.

在执行初始化帐户的所有步骤后, ACAccountStore的 saveAccount:withCompletionHandler:返回 NSURLErrorDomain错误-1012

After performing all the steps to init the account, ACAccountStore's saveAccount:withCompletionHandler: returns NSURLErrorDomain error -1012.

有没有人有类似的问题?

Does anyone have similar issues?

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

My code sample below is using requestToken to init ACAccountCrendential. This object is an OAToken (ShareKit object) initialized with the token and secret received from twitter after completing 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]);
                }
            }];
        }
    }]; 

奇怪的是Apple的 Accounts Framework Reference 建议 saveAccount:withCompletionHandler:尝试执行 OAuth 本身:

The strange thing is that Apple's Accounts Framework Reference suggests that saveAccount:withCompletionHandler: attempts to perform OAuth itself:


如果帐户类型支持身份验证且帐户不是通过身份验证,帐户使用其凭据进行身份验证
。如果验证成功,则保存帐户;否则,它不会被保存。

If the account type supports authentication and the account is not authenticated, the account is authenticated using its credentials. If the authentication is successful, the account is saved; otherwise, it is not saved.

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

I find that very strange since there is no way for the user to authenticate directly with the server by inputting username/password.

我还尝试用我的应用程序的消费者密钥和消费者密钥初始化 ACAccountCredential ,结果相同(失败了 NSURLErrorDomain错误-1012。

I also tried to initialize ACAccountCredential with my application's consumer key and consumer secret, with the same result (failed with NSURLErrorDomain error -1012.)

非常感谢有关此主题的任何指导!

Any guidance on this topic would be greatly appreciated!

谢谢。

推荐答案

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

I'm having the same trouble adding a Twitter account with ACAccount. However, I was able to create a Twitter account with ACAccount successfully using an authorized OAuth Access token and Access token secret, not the Consumer key and Consumer secret. (dev.twitter.com/apps->Twitter->OAuth->OAuth Setting-->Access token and Access token secret) This means that you still have to use an OAuth library to get an authorized Access token and Access token secret when the user is adding a Twitter account.

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

Update: You can see how Twitter recommends that you migrate existing accounts to iOS5 system accounts here. That link provided me with the best example of how to add an ACAccount.

这篇关于在iOS5上创建twitter ACAccount时出错:NSURLErrorDomain错误-1012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆