Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get different sized media - Twitter API

Tags:

twitter

A Twitter API request may get a tweet with an image, returning JSON that contains something like this (non-relevant bits removed)

["media"]=>
array(1) {
    ...
    [0]=>
    array(14) {
        ...
        ["media_url"]=>
        string(46) "http://pbs.twimg.com/media/XXXXXXXXXXXXXXX.jpg"
        ...
        ["type"]=>
        string(5) "photo"
        ["sizes"]=>
        array(4) {
            ["medium"]=>
            array(3) {
                ["w"]=>
                int(1200)
                ["h"]=>
                int(1200)
                ["resize"]=>
                string(3) "fit"
            }
            ["large"]=>
            array(3) {
                ["w"]=>
                int(2048)
                ["h"]=>
                int(2048)
                ["resize"]=>
                string(3) "fit"
            }
            ...
        }
        ...
    }
}

How do you access the different sized versions of the image? I tried entering "http://pbs.twimg.com/media/XXXXXXXXXXXXXXX_medium.jpg" or "http://pbs.twimg.com/media/XXXXXXXXXXXXXXX_1200x1200.jpg" into the address bar (obviously with real images, as opposed to this example URL) but that doesn't come up with anything

like image 483
binaryfunt Avatar asked Aug 23 '16 18:08

binaryfunt


1 Answers

The syntax is slightly confusing, but is described in the Twitter documentation.

The size name medium needs to be added to the end of the URl.

For example:

  • https://pbs.twimg.com/media/CqnMeKkW8AAYDsc.jpg:thumb
  • https://pbs.twimg.com/media/CqnMeKkW8AAYDsc.jpg:small
  • https://pbs.twimg.com/media/CqnMeKkW8AAYDsc.jpg:medium
  • https://pbs.twimg.com/media/CqnMeKkW8AAYDsc.jpg:large
  • https://pbs.twimg.com/media/CqnMeKkW8AAYDsc.jpg:orig (original size image, with metadata stripped out)
like image 91
Terence Eden Avatar answered Nov 15 '22 10:11

Terence Eden