简体   繁体   中英

Use Twitter profile picture in iOS app

I am using Parse.com as my backend server for an iOS app. I have fairly easily linked Facebook accounts with each of my PFUser's, but some of them have signed up with their twitter accounts. How do I obtain their twitter profile picture to show in my app?

I have search a lot for a solution and it is very confusing as some methods seem to have been deprecated in the Twitter API. I believe it has something to do with an http request, but I am also confused about how to execute that. Is is synchronous or asynchronous? Any help would be very much appreciated.

Someone asked this on the Parse forms here, with a complete code sample. https://www.parse.com/questions/how-do-i-get-a-facebook-or-twitter-users-profile-picture

To summarise though, you need to make a request to Twitter's /user/show endpoint with the "screen_name" of the user. ( https://dev.twitter.com/docs/api/1/get/users/show ) This will return the profile information of that user, including the URL of the profile image ("profile_image_url").

The Parse SDK provides a way to sign this request once the user has added her Twitter account.

NSString * requestString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/users/show.json?screen_name=%@", twitterUserNameOfAuthedUser];
NSURL *verify = [NSURL URLWithString:requestString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:verify];
[[PFTwitterUtils twitter] signRequest:request];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM