Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving twitter user data with iOS Social / Accounts frameworks

Is there a way to get user data (first name, last name, and email) from Twitter using the iOS social/accounts frameworks? I'm able to do it with Facebook, but every SLRequest I make to Twitter returns an empty array.

Here's the code I've got right now. I've tried several URLS with varying parameters, but I haven't had any luck.

- (void)populateTwitterAccount  {
NSURL *twitterURL = [NSURL URLWithString:@"https://api.twitbridge.com/1.1/users/show.json"];

SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:twitterURL parameters:nil];

[twitterRequest setAccount:self.twitterAccount];

[twitterRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    NSString *accountDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    
    NSLog(@"%@", accountDataString);
    
}];

}
like image 975
Bishop Avatar asked Nov 28 '22 08:11

Bishop


1 Answers

yes we can.

 ACAccountStore *account = [[ACAccountStore alloc] init];
 ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSString *message = _textView.text;
//hear before posting u can allow user to select the account
 NSArray *arrayOfAccons = [account accountsWithAccountType:accountType];
 for(ACAccount *acc in arrayOfAccons)
 {
    NSLog(@"%@",acc.username); 
    NSDictionary *properties = [acc dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"properties"]];
    NSDictionary *details = [properties objectForKey:@"properties"];
    NSLog(@"user name = %@",[details objectForKey:@"fullName"]);//full name
    NSLog(@"user_id  =  %@",[details objectForKey:@"user_id"]);//user id 
 } 

for email id, we can also able to get user email id see the updated answer hear

like image 94
Shankar BS Avatar answered Dec 06 '22 16:12

Shankar BS