Is there any way of building a profile image url with user id or screen name? I store user ids in database but i don't want to store profile image url.
edit:
I don't want to make a api call too. I want to put user_id inside a url like
<img src="https://twitter.com/users/profile_pic?user_id=123">
Is there a url to do this?
Well I'm using a tricky way via PHP Dom Parser
This will give you something like this; https://pbs.twimg.com/profile_images/378800000487958092/e04a191de329fcf8d000ca03073ad594_bigger.png
to get 2 other size; for big version remove, "_bigger" for smaller version replace "_bigger" with "_normal"
Introducing the easiest way to get Twitter Profile Image without Twitter API.
Using http://avatars.io/
As @AlexB, @jfred says it doesn't work at all on MOBILE devices.
And it's a quite HARD way to get redirected URL using common frameworks PHP or Javascript in your single page.
Simply call
http://avatars.io/twitter/ruucm
at your image tag.like
I've tested it Angular 2+ and it works but any problem
Based on the answer by @Cristiana214
The following PHP snippet can be used to make the https://twitter.com/[screen_name]/profile_image?size=normal trick work on mobile.
Due to twitters redirect to the mobile version of the site links such as https://twitter.com/[screen_name]/profile_image?size=normal get broken on mobile devices
So the script gets the redirect response (to the user avatar) extracts the address then redirects the page itself
So this could be accesses as twitteravatar.php?id=twitter which (at time of writing) reloads to https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg
Not pretty but works.
With version 1.1, use http://a0.twimg.com/profile_images/XXXXX/afpecvf41m8f0juql78p_normal.png where XXXXX is the User Id
with API 1.1 you can achieved using this url
https://twitter.com/[screen_name]/profile_image?size=mini https://twitter.com/[screen_name]/profile_image?size=normal https://twitter.com/[screen_name]/profile_image?size=bigger https://twitter.com/[screen_name]/profile_image?size=original
Official twitter documentation Profile Images and Banners
Example
You can get it using the
users/show
method of the Twitter API -- it does exactly what you described. You give it a the ID or the screen name, and it returns a bunch of data, includingprofile_image_url
.