Hello, I’m trying to create a system that checks if one user is following another. For this I use the Friends API.
Initially, I used a method that returns a table of user IDs that the player I needed followed to. What was presented in this post as an example. But I refused to use this method because it can sometimes be ineffective if the user has a lot of followings.
I found another method that returns the following status which I want to continue using. But it gives me an “HTTP 403” error.
Here is my code:
local Url = 'https://friends.roproxy.com/v1/user/following-exists'
local RequestIds = {
['targetUserIds'] = {1}
}
RequestIds = HttpService:JSONEncode(RequestIds)
local Response = HttpService:PostAsync(Url,RequestIds,Enum.HttpContentType.ApplicationJson)
Response = HttpService:JSONDecode(Response)
What’s the problem? Perhaps I didn’t provide enough necessary arguments or something like that? Some people say they need to get an X-Csrf-Token or a .ROBLOSECURITY cookie. I’m not quite sure how to do this automatically…
Also when I was looking for a solution to the problem, I found this:
I tried running this through the GetAsync method, but I got a “404” error. Apparently, it is not intended for this method.
I’m new to using APIs and don’t understand them very well. If my suggestion is possible, please tell me how to do it right. I’d be very grateful!
The endpoint you’re trying to use (/v1/user/following-exists ) requires an X-CSRF-Token and a .ROBLOSECURITY cookie. it’s an authenticated endpoint built for the roblox website not for game servers. the original get approach you had was correct the only problem was efficiency and you can easily solve that by paginating properly so instead of loadinag every single following at once you can fetch 100 at a time and stop the moment you find the target, most checks will resolve in a single request
function isFollowing(userId, targetId)
local cursor = ""
for page = 1, 50 do
local url = "https://friends.roproxy.com/v1/users/" .. userId .. "/followings?limit=100&sortOrder=Desc" .. (cursor ~= "" and "&cursor=" .. HttpService:UrlEncode(cursor) or "")
local ok, res = pcall(function() return HttpService:JSONDecode(HttpService:GetAsync(url)) end)
if not ok then return false end
for _, entry in ipairs(res.data) do if entry.id == targetId then return true end end
cursor = res.nextPageCursor
if not cursor or cursor == "" then break end
task.wait(0.15)
end
return false
end
print(isFollowing(5355599125, 156) and "They are following!" or "Not following.")```
In addition to what has been said above, I would also advice to make API requests in a smart manner. For example if player A follows player B, you can check it by either checking if player B exists in followings of A, or if A exists in followers of B. Two completely different lists.
A good strategy to minimize requests is to call the API that returns less pages. Pages are directly correlated to the total amount of followers/followings, there are public endpoints you can use to fetch that. Your goal should be to fetch the smaller list so you do less requests. For example if you know player A is famous (for example a developer) it’s better to check through the followings of B.
Also always have a page rate limit in place, there’re accounts out there (like the one of builderman) with thousand or millions of followers/followings.