I’m trying to get my website to display the total number of place visits, although I am having a hard time with JavaScript / cross-domain protection. Is there a web api I can use to get the visits to show up on an external cross-domain site?
Thanks
I’m trying to get my website to display the total number of place visits, although I am having a hard time with JavaScript / cross-domain protection. Is there a web api I can use to get the visits to show up on an external cross-domain site?
Thanks
I’m not sure if this can be accessed from a different domain, but I know that Roblox is trying to expand this API. Note that it is in active development and likely to change though. https://games.roblox.com/docs shows all the current API calls, but https://games.roblox.com/docs#!/Games/get_v1_games_placeId_servers_serverType is the one you want. There isn’t a ‘get how many players are playing this game’ but there is a ‘get the active servers of this game’ which also returns the number of players per each server. This probably wont be suitable to update often or for games with a large number of servers though.
To find this web API and others, you can use one of the many pentest tools out on the web to find the subdomains of Roblox. Using the free scan from pentest-tools.com allowed me to see that Roblox owns 44 subdomains, of which these guys sound like APIs:
avatar.roblox.com
abuse.roblox.com
catalog.roblox.com
chat.roblox.com
locale.roblox.com
games.roblox.com
images.roblox.com (seems to have some protection around it)
setup.roblox.com (same as above)
api.roblox.com (woah! This one has a ton of api calls… super useful!)
ads.roblox.com
In general appending a /docs will bring you to a html page describing the api.
Here’s some web scraping code I wrote in Node.js a while ago for getting the amount of players playing a game, it’s pretty messy as I was inexperienced with web scraping. However this should help you to figure out how to write your code for getting game visits. (On mobile sorry for bad indentation and lack of more support, didn’t have time to write code for your specific case)
Basically this requires cheerio to parse the response body of a GET request we send to the game page of your choice. Then I viewed the page source (Right Click > View Page Source) on chrome and found that the player count was under the ‘li.game-stat’ as ‘p.text-lead’.
var cheerio = require('cheerio');
var request = require('request');
let playerNumbers = [];
request({method: 'GET', url: 'URL_OF_PLACE'}, function(err,
response, body) {
if (err) return console.error(err);
$ = cheerio.load(body);
$('li.game-stat').each(function() {
playerNumbers.push(JSON.stringify($('p.text-lead', this).text()))
});
let playerNo = playerNumbers[0].replace(/['"]+/g, '');
console.log(playerNo)
})
Here’s a more cleaned up easy to use promise function that a member of the ROBLOX API server (@Atlasiane) wrote for me after I did mine. (Thanks mine was horrible).
function fetchNumPlayersInGame(placeUrl) {
return new Promise((resolve, reject) => {
request(placeUrl, (err, response, body) => {
if (err) reject(err)
else {
let $ = cheerio.load(body)
resolve($('.game-stat .text-lead').first().text())
}
})
})
}