Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user profile image from logged user with Twitter Kit/Fabric in iOS

i'm using Fabric in order to add a "Sign In with Twitter" button in my app. Sign in process works fine, but I don't how (if it's possible) how to get the logged user's profile image.

Is there any property inside TWTRSession with this info (like userName and userID)? Looked for it but I didn't found anything?

[TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
  // I get user data here...
  // and need to get user Twitter's profile image
}];

Thanks

EDIT

Thanks to sak's answer, i figured out how to do it.

[TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
  [[[Twitter sharedInstance] APIClient] loadUserWithID:session.userID completion:^(TWTRUser *user, NSError *error) {
       NSLog(@"User image %@", user.profileImageURL);
  }];
}];
like image 673
WedgeSparda Avatar asked Feb 20 '15 16:02

WedgeSparda


2 Answers

For those who are getting this error :

Value of type 'Twitter' has no member 'APIClient'

This helped me,

let twitterClient = TWTRAPIClient(userID: userID)
twitterClient.loadUserWithID(userID) { (user:TWTRUser?, error:NSError?) in
    print(user?.profileImageURL)
}
like image 141
Mohammad Zaid Pathan Avatar answered Sep 20 '22 09:09

Mohammad Zaid Pathan


Try below code to get profile image -

Swift 3

let twitterClient = TWTRAPIClient(userID: session?.userID)
    twitterClient.loadUser(withID: (session?.userID)!, completion: { (user, error) in
       print(user!.profileImageURL)
})
like image 31
Abhishek Jain Avatar answered Sep 22 '22 09:09

Abhishek Jain