Game Browser IGDB integration
It's data time. We'll learn how to get authorization and query game data with filters from IGDB API.
Time to get some data from IGDB
This time we’ll talk about how we can retrieve data from IGDB API, and what steps we need to take before we can even try to retrieve any data.
At the end of this post you will get data like this Baldur’s Gate search result from IGDB API.
Let’s install the tools that help us build the backend:
Postman is a application you can run on your desktop, for example on Windows. It allows us to manually send HTTP requests, such as GET, PUT, POST, etc. It is very handy for testing and debugging purposes.
Note that this is not an absolutely must, because our backend service does not use Postman. It is solely for the purpose of trying out our queries manually. And for this post, it is good for demonstration purposes as well.
To use IGDB API, you must:
Have a Twitch account
Enable two-factor authentication in Twitch
Register your application in Twitch developer portal
Take a note of your application’s Client ID
Create a new secret, and store the Client secret safely (you can’t view it from Twitch developer portal at a later time)
You must have Client ID and Client secret available when you get authorization to use IGDB. Do not share these values with anyone.
So IGDB uses Twitch’s authorization services, and those are implemented with OAuth2 authorization protocol.
As a side note it is good to understand, that OAuth2 is not an authentication protocol, but a authorization protocol. The difference between the two are, that authentication means only identifying who you are. It does not define what you can see or do, once you are in the system. Authorization defines just that: what resources you can see and what you can do with the resources.
To get authorization to use IGDB, we must send a POST request to IGDB. The address to send the request to is always:
We need to attach more information to the request though - the parameters OAuth2 uses for authorization:
The first two are own client’s values, and only you know those (from Twitch developer portal). The third, grant_type, has always value client_credentials.
So the final request looks like this:
https://id.twitch.tv/oauth2/token?client_id=<your client_id here>&client_secret=<your client_secret here>&grant_type=client_credentials
With Postman, it is very easy to create a query like this: