twitchtv / igdb-api-python

Python wrapper for IGDB API version 4
MIT License
75 stars 9 forks source link

Main Readme example does not work #5

Closed dnola closed 4 years ago

dnola commented 4 years ago

Hello,

I signed up for a Twitch developer account, registered my application, and did the following - as per the readme:

from igdb.wrapper import IGDBWrapper
wrapper = IGDBWrapper("<my info>", "<my info>")

byte_array = wrapper.api_request(
            'games',
            'fields id, name; offset 0; where platforms=48;'
            )

and immediately receive the following error:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-13-23d4b721e7e8> in <module>()
      3 byte_array = wrapper.api_request(
      4             'games',
----> 5             'fields id, name; offset 0; where platforms=48;'
      6             )
      7 # parse into JSON however you like...

1 frames
/usr/local/lib/python3.6/dist-packages/requests/models.py in raise_for_status(self)
    939 
    940         if http_error_msg:
--> 941             raise HTTPError(http_error_msg, response=self)
    942 
    943     def close(self):

HTTPError: 403 Client Error: Forbidden for url: https://api.igdb.com/v4/games

Any advice? Thank you!

dnola commented 4 years ago

Nevermind, got it! I got my client secret and my access key mixed up. I actually needed to do this:

from igdb.wrapper import IGDBWrapper import requests import json

r = requests.post("https://id.twitch.tv/oauth2/token?client_id=[my info]&client_secret=[my info]&grant_type=client_credentials") access_token = json.loads(r._content)['access_token'] wrapper = IGDBWrapper([my info], access_token)