21

I'm trying to get last 5 tweets from a person. I did it, but profile picture is not looking normal, resolution is corrupted. like that. ! http://i.hizliresim.com/wLQEJZ.jpg

var $twitter = $('#twitter');

    $.getJSON('http://www.demo.net/twitter.php?username=yeniceriozcan&count=5', function(data){
        var total = data.length,
            i = 0;
        $twitter.html(''); // önce içindekini temizle sonra tweetleri yazdır.
        for ( i; i < total; i++ ){
            var tweet = data[i].text; // tweet
            var date = parseTwitterDate(data[i].created_at); // tarih
            var image = data[i].user.profile_image_url; // profil resmi
            var url = 'https://twitter.com/' + data[i].user.screen_name +'/status/' + data[i].id_str;
            $twitter.append('<div class="tweet"><a target="_blank" href="' + url + '"><img src="' + image + '" alt="" class="profile-image" />' + tweet + '</a> <span class="tweet-date">(' + date + ')</span></div>');
        }
    });

This is my code. I tried to that for to get profile picture,

var image = data[i].user.profile_image_url;

And also in other tweets file,

$tweets = $twitter->get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name='.$username.'&count='.$count);

print json_encode($tweets);

I used this api.

but I can not view pictures in normal resolutions. How can I fix it? Thanks.

user2674354
  • 298
  • 2
  • 3
  • 12

4 Answers4

48

I found that using bigger still brought the picture back in a relatively small format. Using this answer enables you to resize the image allowing you to have a big image without distortion.

If you want to get the image full size just get rid of the "_normal" completely

http://pbs.twimg.com/profile_images/429221067630972918/ABLBUS9o_normal.jpeg

Goes to

http://pbs.twimg.com/profile_images/429221067630972918/ABLBUS9o.jpeg

Note: The urls in this answer are modified so as to not reflect my twitter details hence why entering them will give you a "no page exists"

sam_smith
  • 6,023
  • 3
  • 43
  • 60
  • 1
    Note that the full size images can be quite large in filesize – binaryfunt Aug 23 '16 at 18:10
  • 1
    Some images are not available without the size definition like "_normal" or "_bigger". For example https://pbs.twimg.com/profile_images/481123524329734146/jk4aTqws_normal.png – jazz Dec 08 '17 at 11:27
24

When you read the url from data[i].user.profile_image_url, replace "_normal" with "_bigger". Here's the explanation from the Twitter docs:

User Profile Images and Banners

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
16

Update December 22nd 2020

This is still the case - works.

Update May 6th 2017

When you get the user's profile image via profile_image_url or profile_image_url_https (see User Profile Images and Banners), try to replace "_normal" at the end of the filename with "_400x400".

Seems that they are now scaling images down to 400x400 and then delete the original file.

philippzentner
  • 396
  • 2
  • 11
  • 1
    Welcome to SO. Please read this [how-to-answer](http://stackoverflow.com/help/how-to-answer) for providing quality answer. – thewaywewere May 06 '17 at 19:53
  • Edited my answer. – philippzentner May 06 '17 at 20:30
  • Where did you find this dimension `_400x400`? There is no any info about `400x400` in your link – Green Aug 24 '17 at 06:02
  • @Green They don't document it. I linked to the docu to show how their image-urls are structured. I simply figured it out by myself: Just go on your Twitter profile, click on your profile image and copy image address - there you can see it. – philippzentner Jan 10 '18 at 11:32
12

In case you still need this questions answered (since none of the previous ones are marked as an accepted answer) this is how I managed to deal with the Twitter API image URL sizing:

Grabbing the URL from the API will return the "http" and "https" URL's in the following format(s):

http:

http://pbs.twimg.com/profile_images/378812345851234567/Ay2SHEYz_normal.png

https:

https://pbs.twimg.com/profile_images/378812345851234567/Ay2SHEYz_normal.png

For whatever reason Twitter decided that a 48x48 png was good enough. If you want the full resolution you need to remove the "_normal" tag from either URL, as angryTurtle stated above. This will give you the URL of the full size image. Here is quick example work around of accomplishing this:

/// remove '_normal' from picture url to get full size
        NSString *TWTRPicStringF = [twitterProfilePictureURLStringN stringByReplacingOccurrencesOfString:@"_normal" withString:@""];

Hopefully this helps you and you can mark one of these as the accepted answer to close the question!

FYI: I also have modified the URL contents to protect my own Twitter information, explaining the "no page exists" when using one of the provided URL's above.

Community
  • 1
  • 1
Will Von Ullrich
  • 2,129
  • 2
  • 15
  • 42