How do I make a Twitter verification system? (Check if a user is following me)

I’m trying to make a system in my game where a player can type in their Twitter handle, and it will send a request to Twitter’s API checking whether that account is following me. I know that I need to use the API and I have a Twitter Developer account, but apparently I need to authorize the request with my token or something like that, and I have no idea how to go about it. Any and all help is highly appreciated!

1 Like

To use the Twitter API to check if a user is following you, you will need to follow these steps:

  1. Set up a Twitter Developer account and create a developer app. This will give you access to the API and provide you with the necessary credentials (e.g. consumer key, consumer secret, access token, access token secret) to make authorized requests.
  2. Install an HTTP library for Lua, such as HttpService , to make HTTP requests to the Twitter API.
  3. Use the HttpService to send a GET request to the followers/ids endpoint of the Twitter API, along with the necessary authentication parameters and the screen name of the user you want to check.
  4. Parse the response from the API and check if the user’s ID is included in the list of follower IDs. If it is, the user is following you.

Here is an example of how you could implement this in a Roblox game using the HttpService :white_check_mark:

local HttpService = game:GetService("HttpService")

-- Replace these with your own API credentials
local consumerKey = "your_consumer_key"
local consumerSecret = "your_consumer_secret"
local accessToken = "your_access_token"
local accessTokenSecret = "your_access_token_secret"

-- Set the screen name of the user to check
local screenName = "twitter_handle"

-- Set the API endpoint and the required parameters
local endpoint = "https://api.twitter.com/1.1/followers/ids.json"
local params = {
  screen_name = screenName,
  count = 5000,
  stringify_ids = true
}

-- Encode the parameters as a query string
local queryString = HttpService:UrlEncode(params)

-- Set the authorization header
local authHeader = HttpService:GetOAuth2Header(endpoint, "GET", queryString, consumerKey, consumerSecret, accessToken, accessTokenSecret)

-- Send the request to the API
local response = HttpService:GetAsync(endpoint.."?"..queryString, {Authorization = authHeader})

-- Parse the response as JSON
local data = HttpService:JSONDecode(response)

-- Check if the user's ID is in the list of follower IDs
local userId = 1234567890 -- Replace with the user's ID
if table.find(data.ids, tostring(userId)) then
  print(screenName.." is following you!")
else
  print(screenName.." is not following you.")
end

This script sends a GET request to the followers/ids endpoint of the Twitter API, along with the necessary authentication parameters and the screen name of the user you want to check. It then parses the response as JSON and checks if the user’s ID is included in the list of follower IDs. If it is, the user is following you.

I hope this helps!

are you just replying to every topic with a chatGPT answer?

4 Likes

This didn’t work, by the way.

1 Like