If player follows twitter account

Hey there.

I’d like to make a system where it verifies if the player follows an specific Twitter account and I have no idea at all on how to accomplish this. I’ve searched on DevForum and Google in general and haven’t found anything even though I’ve seen several games doing this.

Thanks in advance hehe

2 Likes

you can probably get them to enter their @ and then get the list of follows of your chosen twitter account by using the twitter api

1 Like

If it doesn’t bother you, I’d like an script example, I did read HTTPService Roblox API and the Twitter API but I cannot figure it out.

1 Like

Its a nightmare :sob: :sob: :sob: :sob: ( DONT DO IT )


  • get an auth access thingy
local HttpService = game:GetService("HttpService")

local AuthLink = "https://api.twitter.com/oauth2/token"
local Encode = nil -- monstrosity at the bottom

local function GetAuth(ConsumerKey, SecretKey)
	local Data = HttpService:PostAsync(
		AuthLink,
		"grant_type=client_credentials",
		Enum.HttpContentType.ApplicationUrlEncoded,
		false,
		{Authorization = "Basic " .. Encode(ConsumerKey.. ":" .. SecretKey)}
	)

	return string.gsub(
		HttpService:JSONDecode(Data).access_token,
		"%%%x%x",
		function(Replacement) 
			return string.char(tonumber(string.sub(Replacement, 2), 16)) 
		end
	)
end

Encode = function(data)
	-- gotta add in the credits
	-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
	-- licensed under the terms of the LGPL2

	local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
	return ((data:gsub('.', function(x) 
		local r,b='',x:byte()
		for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
		return r;
	end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
		if (#x < 6) then return '' end
		local c=0
		for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
		return b:sub(c+1,c+1)
	end)..({ '', '==', '=' })[#data%3+1])
end
  • Get the user’s followers
local Auth = GetAuth(ConsumerKey, SecretKey)

local function GetFollowing(UserId: number, ScreenName: string?, Cursor: string?, Count: number?, SkipStatus: boolean?, IncludeUserEntities : boolean?)
	local Parameters = {["user_id"] = UserId, ["screen_name"] = ScreenName, ["cursor"] = Cursor, ["count"] = Count, ["skip_status"] = SkipStatus, ["include_user_entities"] = IncludeUserEntities}
	local Url = FillParameters("https://api.twitter.com/1.1/followers/list.json", Parameters)

	return HttpService:GetAsync(Url, true, {Authorization = "Bearer " .. Auth)
end

Full code:
local HttpService = game:GetService("HttpService")

local AuthLink = "https://api.twitter.com/oauth2/token"
local ConsumerKey = ""
local SecretKey = ""

local function Encode(data)
	-- gotta add in the credits
	-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
	-- licensed under the terms of the LGPL2
	
	local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    return ((data:gsub('.', function(x) 
        local r,b='',x:byte()
        for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
        return r;
    end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
        if (#x < 6) then return '' end
        local c=0
        for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
        return b:sub(c+1,c+1)
    end)..({ '', '==', '=' })[#data%3+1])
end

local function FillParameters(Url, Parameters)
	local FilledParameters = 0

	for Parameter, Filled in pairs(Parameters) do
		if Filled then
			Url = Url .. (if FilledParameters > 0 then "&" .. Parameter .. "=" else "?" .. Parameter .. "=") .. Filled
			FilledParameters += 1
		end
	end

	return Url
end

local function GetAuth(ConsumerKey, SecretKey)
	local Data = HttpService:PostAsync(
		AuthLink,
		"grant_type=client_credentials",
		Enum.HttpContentType.ApplicationUrlEncoded,
		false,
		{Authorization = "Basic " .. Encode(ConsumerKey.. ":" .. SecretKey)} -- WHY DO I HAVE TO ENCODE IT
	)

	return string.gsub(
		HttpService:JSONDecode(Data).access_token,
		"%%%x%x",
		function(Replacement) 
			return string.char(tonumber(string.sub(Replacement, 2), 16)) 
		end
	)
end

local Auth = GetAuth(ConsumerKey, SecretKey)

local function GetFollowers(UserId: number, ScreenName: string?, Cursor: string?, Count: number?, SkipStatus: boolean?, IncludeUserEntities : boolean?)
	local Parameters = {["user_id"] = UserId, ["screen_name"] = ScreenName, ["cursor"] = Cursor, ["count"] = Count, ["skip_status"] = SkipStatus, ["include_user_entities"] = IncludeUserEntities}
	local Url = FillParameters("https://api.twitter.com/1.1/followers/list.json", Parameters)

	return HttpService:GetAsync(Url, true, {Authorization = "Bearer " .. Auth})
end

it should return like this

2 Likes

For most games, I believe they just check to see if you wait off the screen for a bit and if you did then it says you followed them :smiley:

if you have >200 followers

I recommend using the next_cursor on the cursor of the GetFollowing function

1 Like

its probably because they did a different method

local Followers = {}

local function CheckIfFollowing(man)
	return table.find(Followers, man)
end

local function RefreshFollowers()
	-- IM NOT DOING IT AGAIN
end
RefreshFollowers()

while task.wait(50) do
	RefreshFollowers()
end
1 Like

yeah because using the api is a hassle just for a tiny follow, its no method, its just waiting.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.