如何在iOS 6中从Twitter获取用户信息?

4

我正在尝试将iOS 6和Twitter集成,使用slcomposeviewcontroller发送推文,但我无法弄清如何从Twitter账户获取用户信息。

有人可以帮帮我吗?


你能否更好地解释一下你做了什么以及你想要什么?http://www.whathaveyoutried.com - Daniele B
我想显示用户的名称和关注者数量。 - user991278
1个回答

11
你走在正确的轨道上,但你使用了错误的框架。社交框架中的SLComposeViewController类仅用于分享。如果您想获取有关当前已登录帐户的信息,则必须使用账户框架
#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);
            }
        }
    }];
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接