Roblox API Problems

What do I want to achieve?

I want to be able to send a request to a API, and be able to get a reponse from it.
(Friends Api)

Example

local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
local url = "https://friends.roblox.com/v1/users/"..player.UserId.."/friends"
local data = HttpService:GetAsync(url)
print(data)
end)

What is this code trying to achieve?

I want the code written above, to be able to:
1.) Get the friends a player has
2.) check each of the friends JoinDates
3.) Print out each of the friends AccountAge

So whats the problem?

The problem is, I don’t know how to do this. It seems simple enough but apparently after doing a bit of research, roblox blocks API requests from it’s own game… So yeah I have heard about making proxys and all that, but I am not going to make a whole proxy just to access a roblox API…

Have I done research?

I have been looking into this for around 3 days now, and the only solution I see is “make a proxy”, which I am not willing to do, so if their is another solution please let me know.

You can use Roproxy or just use Players:GetFriendsAsync

1 Like

Does Players:GetFriendsAsync() have the friends data like their account age and what not? If so how do I access it?

It does not give the age, it gives the id, username, display name, and a boolean if the player is online, you can use the GetFriendsOnline() which gives more info.

There’re a few built-in functions you can use but to send a friend request outside of the same server you will need to use the API and a proxy.

(Sorry i replied to wrong person)

Instead of this URL, use

local url = "https://friends.roproxy.com/v1/users/"..player.UserId.."/friends"

It is using a proxy instead of sending the request directly to roblox

First to get the join date of a user the friends API is not sufficient and you will have to use the users API, specifically this endpoint: https://users.roblox.com/docs#!/Users/get_v1_users_userId (get the created field)

To get a user’s account age you can simply calculate it using the created field returned by the endpoint linked above

Finally it is to note that this API request will fail as roblox blocks requests coming from a game’s servers: you need a proxy

1 Like

https://developer.roblox.com/en-us/api-reference/property/Player/AccountAge

For active players.

Yourself mention “For active players”, that is why i did not tell to use the AccountAge property as almost certainly not all friends will be online at the same time so for some the account age could not be obtained.

If a friend is in the game it’d be more efficient to index their ‘AccountAge’ property than perform an external API request.

Since OP wants to get all user’s friends (and he needs an API request for it) it seems faster to me to calculate the AccountAge from the returned creation date as he will need a function to do so for friends that are not in the game

You’d use the external API for offline friends and the internal ‘AccountAge’ property for online, in-game friends.

There is the GetFriendsAsync function to get friends but it won’t return the account creation date so he would need to:

  1. Get the friends with that function (that doesn’t return the property he needs)
  2. Check for who is in the game and who’s not
  3. Make an API request for offline friends

Instead directly making an API request would take only 2 steps:

  1. API request to get all the friends (receiving the creation data too which the OP will need and will work for online and offline players)
  2. Calculate the account age using the “created” property returned by the API

The number of steps taken is inconsequential, internal API methods are far more efficient than external ones.

Players:GetPlayerByUserId(FriendId) --Quick and simple way to determine if a player is online.

Honestly this looks like over optimization to me, then it’s up to op