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


Is there any way to have a live group member count?
#2

<3!


#3

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


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