保存Twitter ACAccount时为什么会出现此错误? [英] Why I get this error when saving Twitter ACAccount?

查看:296
本文介绍了保存Twitter ACAccount时为什么会出现此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Twitter帐户保存到 ACAccountStore

I'm trying to save a Twitter account into the ACAccountStore.

我正在使用 MPOauth 对用户进行身份验证(这完全正常,我可以验证并发布消息)和当我收到访问令牌和访问令牌秘密时,我继续保存帐户。

I'm authenticating the user with MPOauth (this works perfectly, I can authenticate and post a message) and when I receive the access token and the access token secret I proceed to save the account.

首先,我将令牌访问权限分开,只取得令牌本身,而不是用户ID。之后这是我的代码

First of all, I split the token access for taking only the token itself, not the user ID. After that this is my code

if ([username length] > 0 && [token length] > 0 && [secret length] > 0) {

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    ACAccount *account = [[ACAccount alloc] initWithAccountType:accountType];
    ACAccountCredential *credentials = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];

    [account setCredential:credentials];
    [account setUsername:username];

    [accountStore saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {

        if (success) {

            NSLog(@"the account was saved!");

        } else {

            NSLog(@"the account was NOT saved");
        }

        [accountStore release];
        [account release];
        [credentials release];
    }];
}

但从来没有用,我得到这个

But never works, I get this

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)"

我读到这是针对在Twitter上验证数据的错误,这是在保存帐户之前由iOS5框架完成的事情。

I read that this responds to an error authenticating the data against Twitter, thing that is done by iOS5 framework before saving the account.

我已经阅读了此响应以及 Twitter 中的帖子。

I've already read this reponse and the post in Twitter.

有什么问题?

推荐答案

如果令牌是OAToken你应该替换这个

if token is OAToken you should replace this

ACAccountCredential *credentials = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:token];

这个

ACAccountCredential *outhCredential = [[ACAccountCredential alloc] initWithOAuthToken:token.key tokenSecret:token.secret];

你应该传递密钥&秘密分别作为第一和第二个参数。

You should pass key & secret as 1st and 2nd arguments respectively .

这篇关于保存Twitter ACAccount时为什么会出现此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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