Question

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?

Was it helpful?

Solution 2

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;

OTHER TIPS

You can use Fabric Twitter library.

Configuration is very easy:

[[Twitter sharedInstance] startWithConsumerKey:@"_key_" consumerSecret:@"_secret_"];
[Fabric with:@[[Twitter sharedInstance]]];

After it just use:

    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
    if (session) {
        NSString *userID = [Twitter sharedInstance].sessionStore.session.userID;
        TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:userID];
        [client loadUserWithID:userID completion:^(TWTRUser *user, NSError *error) {
            NSLog(@"Profile image url = %@", user.profileImageLargeURL);
        }];
    } else {
        NSLog(@"error: %@", error.localizedDescription);
    }
}];

You need to set

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

instead of Version 1 , use version 1.1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top