Search code examples
objective-ctwitterxcode4.5

How to get twitter profile pics URL in iOS now?


I used to do this:

NSString * strPictureURL = [NSString stringWithFormat:@"https://api.twitter.com/1/users/profile_image?screen_name=%@&size=bigger",strUsername.RobustURLEncodedString];

https://api.twitter.com/1/users/profile_image?screen_name=username&size=bigger

That no longer works anymore. Twitter turn off that API. Well, I am authenticated already. So how do I know?


Solution

  • This is the new way of doing it

                NSDictionary * resp = [NSJSONSerialization JSONObjectWithData:responseData
                                                          options:0
                                                            error:&jsonError];
    
    
                self.strUsername  = [resp objectForKey:@"screen_name"];
                NSString * strPictureURL = [resp objectForKey:@"profile_image_url"];
                strPictureURL = [strPictureURL stringByReplacingOccurrencesOfString:@"_normal" withString:@""];
                self.strPictureURL = strPictureURL;