user991278
user991278

Reputation:

How to get user info from twitter in ios 6?

I'm trying to integrate Ios 6 and twitter to send a tweet using slcomposeviewcontroller, but I cannot figure out how to get user info from twitter account.

Can anybody help me?

Upvotes: 4

Views: 5272

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130222

You were on the right track, but you were using the wrong framework. The SLComposeViewController class in the social framework is only meant for sharing. If you want to get information about the currently signed in account, then you have to use the Accounts Framework.

#import <Accounts/Accounts.h>


- (void)getTwitterAccountInformation
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
        if(granted) {
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

            if ([accountsArray count] > 0) {
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
                NSLog(@"%@",twitterAccount.username);
                NSLog(@"%@",twitterAccount.accountType);
            }
        }
    }];
}

Upvotes: 11

Related Questions