Error creating twitter ACAccount on iOS5: NSURLErrorDomain error -1012

时间秒杀一切 提交于 2019-12-30 12:13:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8224835/error-creating-twitter-acaccount-on-ios5-nsurlerrordomain-error-1012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!