在 iOS5 上创建 twitter ACAccount 时出错:NSURLErrorDomain 错误 -1012

发布于 2024-12-17 09:54:15 字数 1984 浏览 7 评论 0原文

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

执行完初始化帐户的所有步骤后,ACAccountStore 的 saveAccount:withCompletionHandler: 返回 NSURLErrorDomain 错误 -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]);
                }
            }];
        }
    }]; 

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

如果账户类型支持认证且账户未认证,则该账户已认证 使用其凭据。如果认证成功,则保存账户;否则不保存。

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

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

有关此主题的任何指导都将非常有用赞赏!

谢谢。

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

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

Does anyone have similar issues?

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

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.

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!

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2024-12-24 09:54:15

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

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

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文