about 11 years ago
The following code will help you to create your twitter account in your iPhone through coding. Also please note this code will only run in ios7 or later.
- -(void)createTwitterAccount{
- ACAccountStore *store = [[ACAccountStore alloc]init];
- ACAccountType *twitterAccountType = [store
- accountTypeWithAccountTypeIdentifier:
- ACAccountTypeIdentifierTwitter];
- [store
- requestAccessToAccountsWithType:twitterAccountType
- options:NULL
- completion:^(BOOL granted, NSError *error) {
- if (granted) {
- ACAccount *account = [self returnAcAcount:store];
- [store saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
- if (success) {
- //
- }
- }];
- // Step 2: Create a request
- }
- }];
- }
- -(ACAccount *)returnAcAcount:(ACAccountStore *)store{
- // Each account has a credential, which is comprised of a verified token and secret
- ACAccountCredential *credential =
- [[ACAccountCredential alloc] initWithOAuthToken:TWITTER_KEY tokenSecret:TWITTER_SECRET];
- //
- // Obtain the Twitter account type from the store
- ACAccountType *twitterAcctType =
- [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
- // Create a new account of the intended type
- // ACAccountTypeIdentifierTwitter
- ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:twitterAcctType];
- // Attach the credential for this user
- newAccount.credential = credential;
- return newAccount;
- }
-(void)createTwitterAccount{ ACAccountStore *store = [[ACAccountStore alloc]init]; ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierTwitter]; [store requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *error) { if (granted) { ACAccount *account = [self returnAcAcount:store]; [store saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) { if (success) { // } }]; // Step 2: Create a request } }]; } -(ACAccount *)returnAcAcount:(ACAccountStore *)store{ // Each account has a credential, which is comprised of a verified token and secret ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:TWITTER_KEY tokenSecret:TWITTER_SECRET]; // // Obtain the Twitter account type from the store ACAccountType *twitterAcctType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; // Create a new account of the intended type // ACAccountTypeIdentifierTwitter ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:twitterAcctType]; // Attach the credential for this user newAccount.credential = credential; return newAccount; }
0 Comment(s)