For some reason the small application I was working on a few months ago as practice is no longer working. Nothing has changed on my end, I am curious why I am no longer able to query data and why I am now getting this 401 error. I see this is a common discussion question on here. Does anyone have any type of answers for this? Or should I just abandon this API?
------------------fetch request----------------------
function getGameAPI(searchTerm) {
var baseUrl = “https://rawg-video-games-database.p.rapidapi.com/games” + searchTerm;
return fetch(baseUrl, {
“method”: “GET”,
“headers”: {
“x-rapidapi-key”: “***********************************************”,
“x-rapidapi-host”: “rawg-video-games-database.p.rapidapi.com”
}
});
}
const mario = “/mario”
getGameAPI(mario)
.then(function(response) {
console.log(response)
return response.json()
});
------------------ERROR IN CONSOLE---------------------
GET https://rawg-video-games-database.p.rapidapi.com/games/mario 401 (Unauthorized)
Response {type: “cors”, url: “https://rawg-video-games-database.p.rapidapi.com/games/mario”, redirected: false, status: 401, ok: false, …}
Doe mee aan de discussie - voeg hieronder een opmerking toe
Uptown Pokies Casino provides me with an exceptional online gaming experience that I thoroughly enjoy. The user-friendly interface, high-quality graphics, and seamless gameplay offer a truly immersive environment. The vast selection of games available is impressive, ensuring there is always something for every type of player. Whether it be classic table games like blackjack and roulette or exciting slot machines with captivating themes and bonus rounds, Uptown Pokies online https://uptown-pokies.casinologin.mobi/ has it all. Additionally, the secure payment options, fast withdrawals, and reliable customer support instill confidence in their commitment towards ensuring a smooth and enjoyable gaming session. Moreover, the casino’s regular promotions and generous bonuses enhance my overall experience by providing additional opportunities to win big. Overall, based on its outstanding features and stellar performance, I can confidently assert that Uptown Pokies Casino is one of my top choices for online gaming entertainment.
Thanks! I gave that a try and for some reason it now tells me that I am not subscribed to the api 😦
I have this live on github. A branched repo if youd like to look at it. I usually give a crack at it a few times a week but have been utterly stumped.
Github Repo Link
I think maybe my fetch request might be wrong? I’ll post the code below.
//grabs the game information that is searched for
function getGameAPI(searchTerm) {
//joins are platforms selection
var platformsJoined = platforms.join(",");
var baseUrl = “https://rawg-video-games-database.p.rapidapi.com/games”;
var query = baseUrl + “?search=” + searchTerm + “&page_size=100&search_exact=true&platforms=” + platformsJoined;
// var query = baseUrl
//we now limit search terms to 5
console.log(query)
return fetch(query, {
“method”: “GET”,
“headers”: {
“x-rapidapi-host”: “rawg-video-games-database.p.rapidapi.com”,
“x-rapidapi-key”: “**********************************”
}
})
}
$("#find-game").on(“click”, function(event) {
event.preventDefault();
var game = $("#search-game").val().split(" “).join(”-");
getGameAPI(game)
console.log(getGameAPI())
.then(function(response) {
console.log(response, “first response”)
return response.json()
})
.then(function(data) {
console.log(data)
if(data.redirect) {
console.log(‘first condition triggered’)
getGameAPI(data.slug)
.then(function(response) {
return response.json();
})
.then(function(data1) {
console.log(data1);
});
} else {
console.log(‘else condition triggered’)
console.log(data)
})
I could use the help anyone has out there!
Also, the last comment on here as literally been posted multiple times. However, if you go to their api documenation page, it literally explains nothing about how to use the actual api. Of course, maybe I am missing something?
You can go to https://rawg.io/apidocs and register for api key and replace key used in tut with this one and it’ll work