Copy Client Credentials0:54
And let's go ahead and create this. Okay, so we get a clientId right here. So let's grab that. And let's put it in a text file for now. So clientId. And we get a secret as well. And we just have to click new secret. Okay. And there it is. Let's copy it, paste it in.
Generate Access Token1:18
And there it is. Let's copy it, paste it in. And now, if you look at the docs, we have to generate an access token with those pieces of information. So we have to make a POST request to this endpoint with the clientId and the clientSecret, and that will give us an access token which we can use. So let's grab this URL, and let's format it in here. Let me just put everything on one line. Okay, and now let's replace the clientId with ours. So that would be in here.
Okay, and now let's replace the client_id with ours. So that would be in here. And same with the client_secret. Get rid of this and paste ours in. And now let's grab this URL, and let's make a new endpoint for this in our REST client. So let's just say Twitch token, it's a POST request. And the URL, I'll paste in, and if I did this right, we should get an access_token. Invalid client. Sorry, I have a space here. And is secret okay?
Set Up IGDB Request3:08
So let's try that. Let's grab this endpoint. And again, let's make a new request. Say IGDB v4, it's a POST request, paste that in. And let's add the headers. So it's client ID. And our client ID is right here. And we have an authorization token or an authorization bearer token. Say authorization, say bearer. And it's based in our access token.
Update Query Popularity Field4:10
So one more change that's going to affect our app here is the removal of the popularity field. So we're making use of that in our queries. And if you see here, it's been removed for whatever reason. So to measure popularity, I'm just using the totalRatingCount. So let's add that. Actually let me grab the query we're using for popular games. So here's the code. We will grab this query and paste it in here. And let's get rid of the dates.
We will grab this query and paste it in here. And let's get rid of the dates. Let's get rid of this. So there is no and clause. And like I said, popularity doesn't exist anymore. So we should get an error. There we go. Invalidate the field name. So instead of popularity, I'm going to make use of totalRatingsCount. And same for the sorting field, totalRatingsCount.
So instead of popularity, I'm going to make use of totalRatingsCount. And same for the sorting field, totalRatingsCount. And now the most popular game should be on top. According to this API is a totalRatingsCount. Okay. Actually we do want a totalRatingsCount clause here. So we want to check if there's at least a certain amount. So that would ensure that the game is popular or somewhat popular at least. So let's add the and clause here. So and totalRatingsCount is greater than some arbitrary number.
Integrate v4 in Laravel5:35
So let's add the and clause here. So totalRatingCount is greater than some arbitrary number. So 5 is fine. There we go. So GTA 5 is pretty popular. You see the totalRatingCount down there. Okay. So now let's see if we can get this working in Laravel. So I'm going to go to my index.blade.php. I'm just going to work with popular games for now.
So I'm going to go to my index.blade.php. I'm just going to work with popular games for now. Remember this page corresponds to this page. So we have popular games, recently reviewed, most anticipated and coming soon. Those correspond to these Livewire components. So I'm just going to comment these out. And in the final code, I will make sure to add everything back in. So let's modify this to make use of v4 like we just did in our REST client. So first thing is the endpoint. So let's grab this and paste it in here.
So first thing is the endpoint. So let's grab this and paste it in here. And in the final code, I'm going to move this to the config/services.php file. But for now, I'll just put it here. And it is a POST request. And for the headers, again, I'm just going to put it in here for now. And in the final code, I'll put it in config/services.php. And also an .env file. So our headers are client_id and authorization. So let's add that.
So our headers are clientId and authorization. So let's add that. And our clientId is right here. And for authorization, let's add this bearerToken. You can use a withTokens method as well, but I'm just going to do it like this. Okay. And let me just make the cache really quick just to make sure everything works correctly. And I'm also going to change this withOptions method. There is a withBody method now, which allows you to pass in raw body or raw text. So let's get rid of this array. Actually, no, let's get rid of the square brackets.
Test and Fix Laravel Query7:30
which allows you to pass in raw body or raw text. So let's get rid of this array. Actually, no, let's get rid of the square brackets. And let's get rid of the key because that's implied with the method. We can keep the query because we need that. And let's just put it here. And with body has a second parameter, and that's just text/plain. Okay. So let's try and dump popularGamesUnformatted. And let's see if this works. popularGamesUnformatted. And let's see if we're getting a response from the server for version four of the API.
And let's see if this works. Popular games unformatted. And let's see if we're getting a response from the server for version four of the API. And looks like I have an error. Oh, yeah, I forgot to change my query. So let's get rid of popularity. Let's replace it with what I do again, totalRatingCount. Paste that in. Let's sort by totalRatingCount. And let's add that clause here for totalRatingCount has to be at least a certain number. totalRatingCount greater than 5.
And it does. Cool. So these do look like popular games. So I think everything is working. So, yeah, I'll make sure to clean up the code and make sure to put this up on GitHub on a new branch for you.
