Using Google Apps As A api.roblox.com And www.roblox.com Proxy

httpservice
#1

(Thanks to Brad_Sharp for helping me with the JavaScript code)

This tutorial is about a simple idea: Using the www.roblox.com and api.roblox.com web APIs without having to pay for a good host, or having to take a free hose who doesn’t have good limits. This process may be a bit long, but it is worth it to have a reliable provider (Google) able to provide access to the Roblox API at no cost to you.

Step 0: Get Google Apps Script
To create the needed JavaScript, you are going to need to have Google Apps Script. It is free, and it is made by Google. To get to it, you need to go to Google Drive (you do need a google account), go to “New”, go down to “More”, and click “Connect more apps”.
When in the search box, type “Apps” and hit enter. It should be the first thing that shows up. When you find it, click “Connect”

TL;DR: Go to google drive, go to new, go to more, go to connect more apps, and find Google Apps Script.




Step 1: Create The Script
Now, you are actually going to have to create a new script. You can put it into any folder or location in Google Drive. To create the script, go to New, go down to More, then click “Google Apps Script”. You may want to name it to something meaningful.

TL;DR: : See image.




Step 2: Enter the JavaScript Code
This step is fairly simple. Brad_Sharp made a small bit of code that you just need to paste into the script, and remove the existing part.
Pastebin Source: http://pastebin.com/QFtbQpiD
Source:

function doGet(e) {
  var output;
  try
  {
    var query = e.parameter["q"];
    var response = UrlFetchApp.fetch(decodeURIComponent(query));
    output = {"result":"success", "response": JSON.parse(response.getContentText())};
  }
  catch(e)
  {
    output = {"result":"error", "error": "Unable to fetch"};
  }
  return ContentService.createTextOutput(JSON.stringify(output)).setMimeType(ContentService.MimeType.JSON);
}

TL;DR: Replace the code in the script for the code provided above.




Step 3: Publish The Script
This step will be a bit complicated compared to the last steps. You need to make it a public API.

  1. Go to Publish, then to Deploy as web app.
  2. Change who has access to the app to “Anyone, including anonymous”.
  3. Click “Deploy”. When the next window comes up, click “Continue”, and in the window that pops up, click “Allow”
  4. You should now get this window. Don’t close it yet, the given link is important.

TL;DR: See images.




Step 4: Set Up The Module
If you haven’t already, open up Roblox Studio, and insert this module somewhere. You will now need to open it up. Start by getting the script it (in the window, or the page url if you close the window, take the massive string of characters from between /s/ and /exec, or /d/ and /edit if you are using the site url. Then paste it into the ScriptId variable.


TL;DR: Get the script id from the link (massive string of characters) and paste it into the ScriptId in the actual script in Roblox Studio (module link above).





Example Code

local HttpProxy = require(game.Workspace.HttpProxyService:Clone()) --Requires the module. Location will vary by where you place it

--Calls GetAsync to get the "bust" character thumbnail
print(game.HttpService:JSONEncode(HttpProxy:GetAsync("http://www.roblox.com/bust-thumbnail/json?userId=1&height=180&width=180")))
--{"Final":true,"Url":"http://t4.rbxcdn.com/7fce4b7a112122ec0611be343a794a71"}


--Calls GetAsync to get username from the user with the id of 261
print(game.HttpService:JSONEncode(HttpProxy:GetAsync("http://api.roblox.com/Users/261")))
--{"Id":261,"IsOnline":false,"AvatarFinal":false,"Username":"Shedletsky"}


--Calls GetAsync to get the primary group of TheNexusAvenger and Whimzee
print(game.HttpService:JSONEncode(HttpProxy:GetAsync("http://www.roblox.com/Groups/GetPrimaryGroupInfo.ashx?users=TheNexusAvenger,Whimzee")))
--{"Whimzee":{"RoleSetRank":255,"GroupName":"RBXDev","RoleSetName":"Group Owner","GroupId":979242},"TheNexusAvenger":{"RoleSetRank":2,"GroupName":"RBXDev","RoleSetName":"Group Game Managers","GroupId":979242}}

All Roblox web APIs: http://wiki.roblox.com/index.php?title=Web_APIs

If you do have a massive game, you will need to keep in mind the 20,000 request limit per data for the standard user, so you may need another source if you call it per player, however, if you don’t think you will exceed the limit, google will work fine.






If you want to share this post, here is a public link: http://imgur.com/QPl3YWo

64 Likes

Is there any way to have a live group member count?
Catalog API for Homestore
#2

<3!

3 Likes

#3

You are my hero! No more need to make hosting website with the same function. Thanks <3

1 Like

Script stops running for no reason when trying to access APIs, even when using a proxy
#4

@TheNexusAvenger This is a huge time-saver-- thanks!

This proxy works perfectly for most Roblox API, but it returns an error for…
/v1/games/multiget-place-details and
/v1/games/multiget-playability-status
…where (I noticed that) the response is an array instead of a table.

How can I get around this? Thanks!

0 Likes

#5

Just do a JSON parse on the returned data which should convert the new data into something you can work with for python.

1 Like

#6

Thanks for the reply.

I believe TheNexusAvenger’s code already does that. I’m having trouble specifically with fetching an array from those URLs. The others in https://games.roblox.com/docs#/ return tables, and there it works perfectly.

My guess is that the solution is pretty easy for someone who knows how the code actually works… I’m not one of those people

0 Likes

#7

What’s happening is when there’s a table inside a table, most languages use both arrays and objects. However, roblox only had tables. The issue that occurs is when the json parse happens in the python code which turns the data into what you see is an array. A simple fix is to not parse the data in the python script but to send that json info straight over to the roblox script where you can then JSONDecode it.

0 Likes