2

我正在尝试将 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 框架在保存帐户之前完成的。

我已经阅读了此回复和Twitter中的帖子。

怎么了?

4

1 回答 1

0

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

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

有了这个

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

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

于 2012-08-24T07:49:03.497 回答