【问题标题】:Why I get this error when saving Twitter ACAccount?为什么保存 Twitter ACAccount 时出现此错误?
【发布时间】:2012-08-19 18:09:45
【问题描述】:

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

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

首先,我将令牌访问拆分为只获取令牌本身,而不是用户 ID。之后这是我的代码

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

但从来没有用过,我明白了

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

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

我已经阅读了this reponseTwitter 中的帖子。

怎么了?

【问题讨论】:

    标签: ios ios5 twitter acaccount


    【解决方案1】:

    如果令牌是 OAToken 你应该替换它

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

    有了这个

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

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

    【讨论】:

    • 不,它不是 OAToken 对象,我将令牌和秘密作为 NSString 对象传递。反正我也会有同样的问题吧?
    • Arrrrrrghhhhhhh,我很愚蠢 T_T 我将 tokentoken 作为参数传递,而不是 tokensecret。无论如何,这并不能解决问题:-(
    • 问题解决,最终问题解决方案是不拆分token,这个问题(stackoverflow.com/questions/7800675/…)的回答是错误的。
    猜你喜欢
    • 2015-04-25
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 2019-11-03
    • 2017-08-08
    • 1970-01-01
    相关资源
    最近更新 更多