본문 바로가기

Development/IOS & Mac

[iOS] twitter iOS 단말기에 있는 유저 정보 가져오기

프레임워크는 Social.framework 와 Accounts.framework가 필요하다.


m_accountStore = [[ACAccountStore alloc] init];

[m_accountStore requestAccessToAccountsWithType:twitterAccountType options:nil

 completion:^(BOOL granted, NSError *error) {

 

if (granted) {

 

NSArray *accounts = [m_accountStore accountsWithAccountType:twitterAccountType];

ACAccount *twitterAccount = [accounts lastObject];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:twitterAccount.username, @"screen_name", [[twitterAccount valueForKey:@"properties"] valueForKey:@"user_id"], @"user_id", nil];

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter

  requestMethod:SLRequestMethodGET

URL:[NSURL URLWithString:@"https://api.twitter.com/1/users/show.json"]

    parameters:params];

[request setAccount:[accounts lastObject]];

[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

if (error == nil && urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {

NSDictionary *userDic = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];

//usreDic에 정보가 담겨져있다.~!

}//end if

}];

 

} else {

dispatch_async(dispatch_get_main_queue(), ^{

handlerBlock(nil);

});

}//end if

 

 }];