RAWG Video Games Database

फ़्री
द्वारा RAWG | अपडेट किया गया 4 days ago | Gaming
लोकप्रियता

9.7 / 10

लेटेंसी

508ms

सेवा का स्तर

98%

Health Check

N/A

सभी चर्चाओं पर वापस जाएं

401 Unauthorized Access

Rapid account: Jpatterson 933
jpatterson933
3 years ago

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, …}

Rapid account: Amnad
Amnad Commented 6 months ago

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.

Rapid account: Jpatterson 933
jpatterson933 Commented 3 years ago

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)

        var gameNameStr = ' ';
        var playTimeStr = ' ';
        var gameImageStr = ' ';

        for (var i = 0; i < data.results.length; i++) {

            if (data.results[i].playtime > 0) {

                //puts game names into string and stores into local storage
                gameNameStr += data.results[i].name + ", ";
                localStorage.setItem("gameNameStr", gameNameStr);
                
                //puts game play times into a string and stores it into local storage
                playTimeStr += data.results[i].playtime + ", ";
                localStorage.setItem("gameTimeStr", playTimeStr);

                //puts our game images into a string
                gameImageStr += data.results[i].background_image + ", ";
                localStorage.setItem("gameImageStr", gameImageStr);

                //console log our search results
                console.log(data.results[i].name);
                console.log(data.results[i].playtime);
                console.log(data.results[i].released);
                console.log(data.results[i].background_image)

                //this reloads the page
                location.reload();
            }
        }
    }
})

})

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?

Rapid account: Zeu S 2017
ZeuS2017 Commented 3 years ago

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

चर्चा में शामिल हों - नीचे टिप्पणी जोड़ें:

नई टिप्पणियाँ पोस्ट करने के लिए लॉग इन / साइनअप करें