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.