Basically I have a ROBLOX+ API (an API that is user-created that extracts data from the ROBLOX site) and I'm trying to get the game to return the RAP ( Roblox Average Price) from a user using a User ID. I'm using ROBLOX's User ID which is 1 as an example of how I might do so.
Here is the code I have based on the Blog Post on how to get rep (reputation) from someone on ScriptingHelpers.
function getRap(Player) local ID = 1 local link = "http://roblox.plus:2052/inventory?id=".. ID local Service = game:GetService("HttpService") local html = Service:GetAsync(link, false) local string = [[<div>"rap":%d+</div>]] local snippet = html:match(string) RAP = (snippet:match("%d+")) return ("ROBLOX has " .. RAP .. " ") end
I was almost sure this would work, but the only thing the output returned was an error I never seen before.
HTTP 403 (HTTP/1.1 403 Forbidden): - path: user/multi-following-exists, json: {"otherUserIds":[38096393],"userId":38096393} ServerSocialScript Loaded
I can't make sense of it. Is there a fix to this?
Decode it into a Lua table with HttpService's JSONDecode. From there, you can easily index the RAP.
local HttpService = game:GetService("HttpService") local Players = game:GetService("Players") function getRapFromUserId(userid) -- I would suggest passing the player's ID rather than their player object local link = "http://roblox.plus:2052/inventory?id=".. userid local json = HttpService:GetAsync(link, false) -- get the json string local decoded = HttpService:JSONDecode(json) -- decode the json into a lua table we can index local rap = decoded.rap -- index rap from the decoded json return rap -- just return the rap end print(Players:GetNameFromUserIdAsync(1) .. " has a RAP of " .. getRapFromUserId(1) )
EDIT: If you really want to use string:match()
, you made a mistake with your pattern matching. [[<div>"rap":%d+</div>]]
should be [["rap":%d+]]
instead since JSON doesn't even use <tag>
s.