API printing the nil value

Hi, I want to make a system in my game that will give exclusive rewards to the players if they reach some specific amount of views on a YouTube video from our official game’s YouTube channel. I searched for that API, but I didn’t found anything. I so much appreciate it if you can help me with something. Thanks!

I need a solution without using API key.

This isn’t possible anymore without an API key, there are probably paid services that do it

Why don’t you want to use an API key?

I just realized that I can get info about any video with my own API key, but the API doesn’t showing the video’s amount of views.

You can use the YT Metrics API, Metrics  |  YouTube Analytics and Reporting APIs  |  Google for Developers

If you are going to do this, make sure to use PolicyService:GetPolicyInfoForPlayerAsync as this checks if the user can use YouTube

I don’t know how can I use it, just because there’s no any examples of the link (like: https://youtube.googleapis.com/youtube/v3/videos?part=snippet&id=F6PqxbvOCUI&key=AIzaSyCRr4LOd2WeFN9TSLCMLgSDSuXaanjxtYM) or any try out buttons like on Roblox’s swagger.

That link is a JSON, you would need to use HTTPService and JSONDecode for it to work

local HttpService = game:GetService("HttpService")
response = HttpService:GetAsync("URL")
data = HttpService:JSONDecode(response)

I know, but how to get a link that will show amount of views on a YT video if you open it?

I’ve already used this method to retrieve all badges in my game for entering the game just by using an badges API.

The Google API has all the details :slight_smile:

The docs shares the api url: API Reference  |  YouTube Data API  |  Google for Developers


For example: https://youtubeanalytics.googleapis.com/v2/reports?metrics=views,likes,subscribersGained&ids=channel==MINE&startDate=2014-07-03&endDate=2020-06-01&&key=${apiKey}&access_token=${token}

That’s ok, but what should I replace MINE to, and also where can I receive the access token? Or it’s just a cookie?

You likely won’t need that for this, the api I sent explains how to get the view count

This can be found on the Google OAuth 2.0 Client Libraries

1 Like

Oh, I’ve found the solution on internet lol. I just needed to add some additional things to the parameters. (Ex link: https://www.googleapis.com/youtube/v3/videos?part=snippet,status,contentDetails,statistics,topicDetails,localizations&id=F6PqxbvOCUI&key=AIzaSyCRr4LOd2WeFN9TSLCMLgSDSuXaanjxtYM)

I’ve just tried to print the video’s id, but it returns the nil value.

local VideoID = "F6PqxbvOCUI"

	local data = game:GetService("HttpService"):GetAsync("https://www.googleapis.com/youtube/v3/videos?part=snippet,status,contentDetails,statistics,topicDetails,localizations&id="..VideoID.."&key=AIzaSyCRr4LOd2WeFN9TSLCMLgSDSuXaanjxtYM")
	if data then
		data = game:GetService("HttpService"):JSONDecode(data)

It’s printing the etag if I’m trying to print data.etag, but it’s not printing the id if I’m trying to pring the data.items.id.

So, can anyone help me with this thing?