-1

im trying to make a raspberry pi youtube sub monitor and im confused about how to get the sub count from youtube channel in python.an example code to do so would be much appreciated.

2 Answers2

0

Please make yourself familiar with the basic YouTube Data API v3 workflows first.

There are different ways to use the API with Python. Since your application does not seem to be very complex, you could directly perform a request to the API with one of Python's HTTP libraries (depends on your Python version).

Alternatively, you can use the Python client library (examples).

In any case, you will need to register an application and obtain an API key in the Google Cloud Console.

paolo
  • 2,528
  • 3
  • 17
  • 25
0

Make a REST call in PYTHON using this URI request:

GET https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&mySubscribers=true&fields=pageInfo&key={YOUR_API_KEY}

The totalResults key holds the number of subscribers. An example of response I got looked like this:

{
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 5
  }
}

in this case, it's 2 subscribers.

I suggest you study Python Quickstarts code structure and learn how to make the REST call.

Check Subscriptions: list for additional info, especially the Try-It section so you can see the results immediately.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56