Trying to fetch a larger image from Twitch API

81 Views Asked by At

I'm working on a type of backlog website, and the code right now is only fetching a size of 52x72 from the Twitch api. I know it can fetch larger ones I'm jut having trouble figuring out how to change it. Here is the code I have so far

    if (isset($authData['access_token'])) {
        $accessToken = $authData['access_token'];

        // Perform API request to Twitch API for game search
        $url = "https://api.twitch.tv/helix/search/categories?query=" . urlencode($searchTerm);

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            "Client-ID: $clientId",
            "Authorization: Bearer $accessToken"
        ]);
        $response = curl_exec($ch);
        curl_close($ch);

        $data = json_decode($response, true);

        if (isset($data['data'])) {
            $categories = $data['data'];

            foreach ($categories as $category) {
                $boxArtUrl = isset($category['box_art_url']) ? str_replace("{width}", 500, str_replace("{height}", 500, $category['box_art_url'])) : "";
                $searchResults[] = [
                    'name' => $category['name'],
                    'cover_url' => $boxArtUrl,
                ];
            }
        }
    }

Any help would be greatly appreciated.

I've tried manually calling a width/height command but it doesn't effect it. I just want it to return a decent height/width so it's not super tiny on the page.

0

There are 0 best solutions below