Python api issues

Hi I am trying to get these piece of code working it’s Python

I only get and empty response : like IGDB ID:
I have looked at this as well : twitch_misc/authentication/app_access_tokens/python at main · BarryCarlyon/twitch_misc · GitHub

def search_igdb(t, category):
        guess = guessit.guessit(t)
        searchterm = guess.get('title', '')

        # Search for the game on IGDB
        key = "XXXX"
        url = "https://api.igdb.com/v4/games"
        headers = {
            "Client-ID": "XXXX",
            'Authorization': 'Bearer ' + key
        }
        data = f"search \"{searchterm}\"; fields id; limit 1;"
        response = requests.post(url, headers=headers, data=data)

        if response.status_code == 200:
            games = response.json()
            if games:
                game_id = games[0]['id']
                # Construct the IGDB URL
                igdb_url = f"https://www.igdb.com/games/{game_id}"
                return igdb_url
            else:
                return ""
        else:
            print("Error:", response.text)
            return ""
    else:
        return ""

So what’s the api response and status code that you are getting?

You need to log those out and track what’s wrong

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.