Problem with presence API

  1. What do you want to achieve? Keep it simple and clear!

I want to make a game where you can Join other Players.

  1. What is the issue? Include screenshots/videos if possible!

When I execute the /v1/presence/users API, I get this:
image

But when I make a POST request in-game, I get this:
image

Many things are now missing from the table! Anyone know why?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I searched on the DevForum, Internet, etc…

This is the code I’m using if anybody needs it:

-- Services

local HTTP = game:GetService("HttpService")
local ReplicatedS = game:GetService("ReplicatedStorage")

-- Variables

local URL = "https://presence.roproxy.com/v1/presence/users"
local Remote = ReplicatedS:FindFirstChild("Player")

-- Function

local function getPresenceData(plr : Player, userID : number)
	
	local data = HTTP:JSONEncode({
		["userIds"] = {userID}
	})
	
	local succ, response = pcall(function()
		
		return HTTP:PostAsync(URL, data)
		
	end)
	
	if succ then
		
		response = HTTP:JSONDecode(response)
		print(response)
		Remote:FireClient(plr, response)
		
	else
		
		warn("There was an error while accessing presence.roblox.com : " .. response)
		
	end
	
end

Remote.OnServerEvent:Connect(getPresenceData)

And this is the client Script:

-- Services

local UserService = game:GetService("UserService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Variables

local GUI = script.Parent
local Backgrond = GUI:WaitForChild("Background")
local MainFrame = Backgrond:WaitForChild("Main")
local UsernameInput = MainFrame:WaitForChild("Username")
local Username = MainFrame:WaitForChild("UsernameLabel")
local DisplayName = MainFrame:WaitForChild("Displayname")
local UserIcon = MainFrame:WaitForChild("UserIcon")
local placeID = MainFrame:WaitForChild("Place-ID")
local JobID = MainFrame:WaitForChild("Job-ID")
local LastOnline = MainFrame:WaitForChild("LastOnline")
local Remote = ReplicatedStorage:WaitForChild("Player")

-- Functions


local function Input(text : string)
	
	local data = Players:GetUserIdFromNameAsync(text)
	
	Remote:FireServer(data)
	
end


--local function calculateLastOnline(lastOnlineString)
--	local year, month, day, hour, min, sec = lastOnlineString:match("(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+.%d+)Z")

--	if year and month and day and hour and min then
--		return string.format("%02d:%02d:%02d:%02d:%02d", tonumber(min), tonumber(hour), tonumber(day), tonumber(month), tonumber(year))
--	else
--		return "Invalid last online format"
--	end
--end

local function Setup(response)
	if response.userPresences and #response.userPresences > 0 then
		local userPresence = response.userPresences[1]
		print(userPresence)
		local userId = userPresence.userId

		local dn = UserService:GetUserInfosByUserIdsAsync({userId})
		local Un = Players:GetNameFromUserIdAsync(userId)
		local icon = Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

		DisplayName.Text = dn[1].DisplayName
		Username.Text = "@" .. Un
		UserIcon.Image = icon
		placeID.Text = "Place ID: " .. "Not In-Game!" or userPresence.placeId
		JobID.Text = "Job ID: " .. "Not In-Game!" or userPresence.gameId
		--LastOnline.Text = "Last Online: " .. calculateLastOnline(userPresence.lastOnline)
	else
		warn("No user presences found in the response.")
	end
end



UsernameInput.FocusLost:Connect(function(enter)
	
	if enter then
		
		Input(UsernameInput.Text)
		
	end
	
end)

Remote.OnClientEvent:Connect(Setup)

Any help would be much appreciated :slight_smile:

I’m guessing this provides you with more information since you are logged in to roblox on your browser (it uses the Token from the session I believe). However, when sending requests from in game, there is no token being passed into the API.

2 Likes

internal api restricts lots of data and access from the actual apis. best to use a proxy service that routes to the prescence endpoint and fetch your information from there

1 Like

I don’t think you actually can do this since roblox doesn’t allow you to view at what game player is in, if it would, it would violate user’s privacy, so you can only view in which game they’re playing if you’re friends with them and they allow friends or everyone to join the game in privacy settings.

1 Like

Well, I used the “roproxy” proxy and it didn’t work.

1 Like