LoginSignup
16
15

More than 5 years have passed since last update.

Twitter APIで取得したプロフィール画像が小さいので大きいものを取得する

Last updated at Posted at 2015-07-03

Twitter APIで取得できる画像小さすぎて今の時代に合わない・・・
でも面倒だけど大きい画像も取得できます。

ドキュメント
https://dev.twitter.com/overview/general/user-profile-images-and-banners

ドキュメントにはusers/show APIで取得したprofile_image_urlには48ピクセル×48ピクセルの画像が返ってくるよ
この画像サイズはnormalだよ、他のサイズが欲しいならURLを変更してねって書いてある

つまり拡張子の前の_normalって部分を変更してあげればOK

対応表

名前 サイズ URL
normal 48×48 http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_normal.png
bigger 73×73 http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_bigger.png
mini 24×24 http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_mini.png
original original http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3.png

Javaだとこんな感じでreplaceしてしまう

String imageUrl = "http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_normal.png";
String originalImageUrl = imageUrl.replace("_normal", "");
16
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15