0

I'm having problems migrating existing OAuth credentials to ACAccountStore in iOS 5.

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAccount *account = [[ACAccount alloc] initWithAccountType:accountType];
ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:savedToken tokenSecret:savedSecret];
[account setCredential:credential];
[accountStore saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
    if (error) {
        NSLog(@"error saving account: %@", error.description);
    }

    NSLog(@"saved account? %d", success);
}];

The end result being:

2011-10-17 19:09:32.927 League[13731:1b803] error saving account: Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)"
2011-10-17 19:09:32.927 League[13731:1b803] saved account? 0
Matthew Crenshaw
  • 322
  • 1
  • 4
  • 14

1 Answers1

1

This error message is caused by using an incorrect token/secret combination. I was incorrectly trimming the user_id prefix off of the OAuth token.

Matthew Crenshaw
  • 322
  • 1
  • 4
  • 14
  • This is wrong as par this [question](http://stackoverflow.com/questions/12104976/why-i-get-this-error-when-saving-twitter-acaccount/12105212#12105212) – msk Aug 27 '12 at 07:42
  • I don't know where that individual's token/secret is coming from, but this code still works for me. – Matthew Crenshaw Aug 29 '12 at 16:59