Is there a quick way to pull twitter profile image in PHP or Javascript? I need to get the url of the FULL image (not avatar size). Thanks. Any code sample is good.
8 Answers
Twitter has had a nice simple URL.
https://api.twitter.com/1/users/profile_image/abraham
It has size options like "?size=bigger"
You can read more about it on Little known Twitter and TwitterAPI tips and tricks.
Twitter now has documentation up as GET users/profile_image/:screen_name.
Update: Support for this method has been removed from v1.1 of the API. Recommended practice going forward is GET /users/show and cache profile_image_url
locally in your service/app.

- 46,583
- 10
- 100
- 152
-
Looks like Twitter removed support for the method in v1.1. I've updated the answer with the current recommended practice. – abraham Apr 04 '13 at 16:40
-
Looks like the simple url is working again, e.g. **[https://api.twitter.com/1/users/profile_image/gb96](https://api.twitter.com/1/users/profile_image/gb96)** – gb96 May 05 '13 at 10:43
-
1@gb96 That is API v1 which will stop working in one month. API v1.1 does not support that API endpoint. – abraham May 06 '13 at 02:30
-
1See https://dev.twitter.com/docs/user-profile-images-and-banners and https://dev.twitter.com/docs/api/1.1/get/users/show for v1.1 info. – Tom Jun 17 '13 at 19:37
-
The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview – Damian Nov 30 '13 at 07:52
function get_big_profile_image($username, $size = '') {
$api_call = 'http://twitter.com/users/show/'.$username.'.json';
$results = json_decode(file_get_contents($api_call));
return str_replace('_normal', $size, $results->profile_image_url);
}
get_big_profile_image('bobsaget', '_bigger') should return a large avatar: http://a1.twimg.com/profile_images/330305510/n229938150541_9850_bigger.jpg
get_big_profile_image('bobsaget') should return an even larger image: http://a1.twimg.com/profile_images/330305510/n229938150541_9850.jpg

- 1,765
- 1
- 16
- 18
-
1This function is no more working. Any other idea? Any other workaround available? – lomse May 14 '13 at 15:04
-
Not working. Error: {"errors":[{"message":"Sorry, that page does not exist","code":34}]} – Svetoslav Marinov Dec 01 '13 at 06:09
Apologies if this is something that's now known, but I didn't see it documented anywhere during my searches, including the official Twitter docs.
You can add the ?size=original as a parameter, which will return the original uploaded image for the user.
So:
http://api.twitter.com/1/users/profile_image/twitter.json?size=original

- 61
- 1
- 1
Previous answerers have provided the correct answer I wanted to link to original twitter api doc page so you'd know it is actually an official way of doing stuff:
You need to specify ?size=
- bigger - 73px by 73px
- normal - 48px by 48px
- mini - 24px by 24px
http://api.twitter.com/1/users/profile_image/twitter.json?size=bigger http://api.twitter.com/1/users/profile_image/twitter.json?size=normal
http://dev.twitter.com/doc/get/users/profile_image/:screen_name

- 4,354
- 1
- 26
- 28
So, it's not in the docs (http://dev.twitter.com/doc/get/users/profile_image/:screen_name), but it looks like after retrieving the image by specifying any of the three sizes (bigger, normal, mini), you can just remove the suffix before the file extension to get the original image. Hmm... is this safe to use?
For example, this query: api.twitter.com/1/users/profile_image/rrbrambley
Results in: a2.twimg.com/profile_images/931772958/deformed_cropped_headonly_normal.jpg
If I change this url by removing "_normal" then I get the original image: a2.twimg.com/profile_images/931772958/deformed_cropped_headonly.jpg
I know there are apps that use the original image. This must be the way?

- 513
- 5
- 15
When you get original image link, you can modify it to get bigger. http://pbs.twimg.com/profile_images/34543543/image_name_normal.jpg
becomes
http://pbs.twimg.com/profile_images/34543543/image_name.jpg or image_name_bigger, ...
Source: https://dev.twitter.com/docs/user-profile-images-and-banners

- 1,319
- 3
- 22
- 35
I know this isn't the full code sample as requested (because there are several ways of doing this), but do you already have the URL for the avatar? I noticed that turning ".../eric.png" into ".../eric_bigger.png" resulted in the larger image. When "_bigger" already exists, removing it gave me the URL to the original image.
I tested this with several followers' profile images and, when the profile image was > 150px square, worked.

- 2,037
- 2
- 16
- 14
Twitter profile images urls: Bigger: https://api.twitter.com/1/users/profile_image/puneetsindhwani/?size=bigger Original: https://api.twitter.com/1/users/profile_image/puneetsindhwani/?size=original