Box art url is null


#1

Hey, I have this response from new twitch api:

{ “data”: [{ “id”: “493057”, “name”: “PLAYERUNKNOWN’S BATTLEGROUNDS”, “box_art_url”: “https://static-cdn.jtvnw.net/ttv-boxart/PLAYERUNKNOWN’S%20BATTLEGROUNDS-{width}x{height}.jpg” }] }

​Parsing box art url as a string return a null. For me response indicates that it is a string but in docs is written that is an object. If it is indeed an object how it should look as a pojo?


#2

box_art_url is a string, the only reason I can think that the docs say it’s an Object is because it’s a template. It may just be a mistake though.

Just treat it as a string and replace the {width} and {height} with the dimensions you wish to use.


#3

The docs

Match the API output OP has provided

You should JSON parse the response, and the extract resp->data[0]->box_art_url and then substritute/string replace {width} and {height} for number for the dimension of image you need.

So

https://static-cdn.jtvnw.net/ttv-boxart/PLAYERUNKNOWN%27S%20BATTLEGROUNDS-{width}x{height}.jpg

becomes

https://static-cdn.jtvnw.net/ttv-boxart/PLAYERUNKNOWN%27S%20BATTLEGROUNDS-200x300.jpg


#4

can i pass % to the width and height? Or does it have to be in px fixed size?

I’m trying to use it as a background image on a div, what’s the best way if at all possible? Do i have to iterate through the whole array and modify each box_art_url and set the width and height? geez i don’t know who designs twitch’s API :confused:


#5

PX

It lets you pick the size of image you want, rather than have the size dictated by Twitch.