Recently, I’ve been trying to use the Youtube Subscriber API
Code:
---- ROBLOX SERVICES ----
local HttpService = game:GetService("HttpService")
---- PRIVATE VARIABLES ----
local MAX_RESULTS_PER_PAGE = 50
local TARGET_CHANNEL_ID = "" -- YouTube channel id player is supposed to be subscribed to
local API_KEY = "" -- Your API Key
---- URL'S ----
local URL = "https://youtube.googleapis.com/youtube/v3/subscriptions?part=snippet&channelId=%s&maxResults=%d&key=%s"
local NEXT_PAGE_URL = "https://youtube.googleapis.com/youtube/v3/subscriptions?part=snippet&channelId=%s&maxResults=%d&pageToken=%s&key=%s"
---- PRIVATE FUNCTIONS ----
function get_channel_subscriptions(channelId, pageToken)
local URL = pageToken and string.format(NEXT_PAGE_URL, channelId, MAX_RESULTS_PER_PAGE, pageToken, API_KEY) or string.format(URL, channelId, MAX_RESULTS_PER_PAGE, API_KEY)
local success, channelSubscriptions = pcall(function()
return HttpService:GetAsync(URL)
end)
if (success) then
return HttpService:JSONDecode(channelSubscriptions)
else
warn(channelSubscriptions) -- error
return nil
end
end
function get_page_numbers_left(channelSubData)
local pages = 0
local pageInfo = channelSubData.pageInfo
local totalResults = pageInfo.totalResults
local resultsPerPage = pageInfo.resultsPerPage
if (not channelSubData.nextPageToken) then
return pages
end
pages = tostring((totalResults - #channelSubData.items) / resultsPerPage)
if (string.find(pages, ".")) then
pages = tonumber(string.split(pages, ".")[1]) + 1
end
return pages
end
function check_if_subbed_to_channel(subData, targetChannelId)
assert(typeof(targetChannelId) == "string", "targetChannelId must be of type [string]")
for _, v in pairs(subData) do
if (v == targetChannelId) then
return true
end
end
return false
end
---- RETURN FUNCTION ----
return function(channelId)
local channelsSubscribedTo = {}
local pageToken = nil
local channelSubs = get_channel_subscriptions(channelId)
if (channelSubs) then
local pagesRemaining = get_page_numbers_left(channelSubs)
for _, v in pairs(channelSubs.items) do
if (v and v.snippet) then
table.insert(channelsSubscribedTo, v.snippet.resourceId.channelId)
end
end
if (pagesRemaining) then
pageToken = channelSubs.nextPageToken
for i = 1, pagesRemaining do
local pageChannelSubs = get_channel_subscriptions(channelId, pageToken)
if (pageChannelSubs and pageChannelSubs.items and pageChannelSubs.nextPageToken) then
for _, v in pairs(pageChannelSubs.items) do
if (v and v.snippet) then
table.insert(channelsSubscribedTo, v.snippet.resourceId.channelId)
end
end
pageToken = pageChannelSubs.nextPageToken
elseif (not channelsSubscribedTo) then
warn("Failed to retrieve channel subscription info")
return false
end
end
end
return check_if_subbed_to_channel(channelsSubscribedTo, TARGET_CHANNEL_ID)
end
warn("channel sub info has failed to load!")
return false
end
However, the pcall returns a Http Error 403, I’ve seen others set game to public, enable api services, allow http requests, all of which did not work for me. If anyone knows how to fix this, or what is wrong, as this module is very old, I tried manually going to the google api on my web browser and I got the same 403 error. I followed the exact instructions on the original post, but it is 2 years old, so if anyone knows of a better way to check for a player’s subscribers like bubble gum simulator or strucid, please reply.