Google Apps Script to Export Youtube Channel Subscribers List in Google Sheets Automatically
Dec 21, 2025
Buy the full source code of application here:
https://buy.stripe.com/3cs5nEd3zbsY0Rac9A
Show More Show Less View Video Transcript
0:00
Uh hello friends today in this tutorial
0:02
I will be showing you that how basically
0:04
we can export all the YouTube
0:07
subscribers public subscribers list
0:09
inside your Google sheet using Google
0:12
appcript. Basically if you have a
0:14
YouTube channel you are running a
0:16
YouTube channel you will be obviously be
0:18
wanting to get a list of your all your
0:20
subscriber name alongside with their
0:22
channel URL. You can obviously check out
0:25
which people have subscribed to your
0:27
channel. So this will be a very useful
0:28
script which will allow you to export
0:30
the list of all the subscribers
0:32
alongside with all their information. So
0:35
now if I run this script guys, you will
0:37
see that automatically it will run the
0:39
script and uh automatically fetches all
0:42
the public subscribers alongside with
0:45
their information is listed now inside
0:47
this Google sheet. So I have a lot of
0:51
subscribers 26,000. You can see that now
0:53
it has automatically fetched all the
0:56
information. you will see that the name
0:58
of the subscribers of my channel
1:00
alongside with the user ID this is a
1:03
channel ID and this is the actual
1:05
channel. If I check out this I can
1:07
simply click and basically I can go to
1:09
their channel and this is the public
1:12
only the subscription only the people
1:15
which allows the channels to be
1:18
subscriptions to be public only they
1:20
will be shown the private subscriptions
1:22
will not be shown. So in this way guys
1:25
you will see that all the channels that
1:29
they have subscribed to. So this is the
1:33
very easy way by which you can get the
1:35
subscribers
1:38
the names of your subs. You can see my
1:40
channel is subscribed by this user
1:42
coding. You can see 26,000 they are
1:44
listed here. So in this easy way guys
1:47
you can check out your subscribers
1:48
information. You can check out their
1:50
names and alongside with the channel URL
1:53
and on which date they have subscribed
1:56
to your channel and which time you can
1:58
see all this information is returned by
2:00
YouTube API and we are making use of
2:02
Google appcript to directly interact
2:04
with this API. So you can see that it's
2:07
very simple. A total of thousand
2:09
subscribers are returned to you which
2:11
are very often. So I think only it's a
2:16
limit by the API only thousand will be
2:18
returned to you and uh uh I have a lot
2:22
of subscribers 26,000. So only the top
2:25
1,000 subscribers are returned to me.
2:27
This is more than enough that if you
2:28
want to get information about your
2:30
subscribers, the top thousand one is if
2:33
you are giving away some winners, you
2:36
will need to have the information. So
2:38
this is the application we will be
2:40
building guys. So basically I have
2:42
written a complete blog post on my
2:43
tutorial website ninja developer.com. So
2:46
the link is given in the description of
2:48
this video. So if you want to get all
2:50
the source code, you can go to the
2:51
description of this video to get all the
2:54
source code alongside step-by-step
2:55
instruction.
2:57
So now get let's get started by building
2:59
this application guys. So first of all I
3:01
will recommend that you should go to
3:04
Google sheet here. So first of all we
3:07
will Google sheet and we will make a new
3:11
sheet here. So go to Google sheet and
3:14
basically click on go to sheet and
3:16
create a blank sheet and basically you
3:19
can rename this sheet to simply double
3:21
click and simply say here YouTube list
3:26
and you don't need to create anything
3:28
any column here. So automatically it
3:30
will be created by itself. Now you
3:32
simply need to go to extensions tab and
3:34
go to appcript. So here we will write
3:37
the actual code guys which is required
3:39
for this purpose.
3:41
And uh basically what we need to do we
3:43
need to simply go to your project
3:46
settings and here you need to uh just
3:49
tick mark this option show this
3:51
appcript.json man manifest file and
3:54
simply if you go to here this file will
3:58
be shown to you and here you need to add
4:00
some uh
4:02
uh guys you need to add a scope out
4:04
there. So o scope so this is called as
4:08
o2 scopes. So they are simply what
4:11
information that you are uh getting from
4:14
the API YouTube API. So basically we
4:18
need the view as access of your YouTube
4:20
account so that we can view the
4:21
information about our subscribers and
4:24
also the spreadsheet also. So you need
4:26
to add these two scopes out there guys
4:28
which are shown here.
4:35
So I can simply now write these scopes
4:39
out there that is seen here.
4:44
So oath two scopes o sorry oath scopes
4:50
here and basically this will be a simple
4:53
array.
4:56
The first information scope will be
4:58
https www.
5:01
Google APIs
5:06
Google APIs.com/
5:10
YouTube read only. So we are only
5:13
accessing the read scope. So we can't
5:16
upload the video, we can't delete the
5:18
video, we can only read the information
5:20
about our channel. So we just need the
5:22
subscriber list. So that's the scope is
5:24
more than enough. So put a comma. The
5:27
second scope we want is the spreadsheet
5:30
full access. We need can be creating
5:32
spreadsheets or we can delete
5:34
spreadsheets. For that we will be
5:36
writing /
5:39
spreadsheets.
5:41
That's it.
5:44
So you just need to add these two lines
5:46
of code guys. So simply save this. And
5:48
now you need to go to your It is saying
5:51
that invalid
5:54
oath scopes.
5:56
Let me cross check oath. Sorry, S needs
6:00
to be capital here. Sorry guys. So S
6:02
needs to be capital again. Save this
6:05
project. So now the project is saved. Go
6:08
to code.gs file guys. So here we will
6:10
write the actual function for getting
6:13
the subscribers. So first of all we need
6:15
to simply get the sheet URL. So here we
6:18
will simply say that spreadsheet ID.
6:22
So here you just simply need to paste
6:24
the spreadsheet ID and also the sheet
6:26
name. So these are two constant
6:29
variables. So if you go to your sheet
6:31
guys basically this is the ID of the
6:34
sheet here simply in the address bar. So
6:38
what we can say we can simply copy this
6:40
and paste it here.
6:45
And the name of the sheet is this one at
6:48
the bottom. Sheet one. This is the name
6:50
here. You can even change the name as
6:53
well. Sheet one. And after this guys, we
6:57
will make a function which is called as
6:59
get public subscribers.
7:02
This will only get the public
7:03
subscription names out there for you. We
7:07
will create a result variable and this
7:09
time we will use YouTube dot
7:13
subscription subscriptions
7:17
dot list method and basically guys uh
7:20
for using this YouTube keyword here we
7:22
need to add a service. So right here in
7:24
the left hand side create add this
7:27
service which is YouTube data API
7:28
version 3. So inside this our
7:30
subscription data will be returned to
7:32
us. So simply add this service guys. So
7:34
this contains a list method and here we
7:37
will be attaching some arguments guys
7:39
which is subscriber
7:42
snippet. So this will get the subscriber
7:45
information and then we will get the
7:46
snippet and the content
7:50
details.
7:54
So put a comma here and this next option
7:58
it takes is the property called as my
8:01
subscribers.
8:03
So we only need to return the
8:05
subscribers of my channel and also the
8:08
max result property guys. So there is a
8:10
restriction out there at one go how many
8:12
subscribers you can get. So I will put
8:14
the max limit which is 50. So at one go
8:18
it will fetch 50 subscribers and the
8:20
subsequent calls it will fetch more. So
8:23
here we will first of all store the
8:26
token that it returns for the
8:28
pagination. So for the first 50
8:30
subscribers it will have this result dot
8:33
next page token. This is a property and
8:36
depending upon this property guys if
8:38
more if the subscribers are more than 50
8:42
then we will run it for the second time
8:44
as long as we will store these
8:46
subscribers first of all subs. This will
8:49
be the array here which will have the
8:52
property result dot items and after this
8:55
we will use a simple while loop guys. So
8:58
here we will simply check for the next
9:00
page token. As long as this value is not
9:03
equal to null then we will perform these
9:06
operations which is again we will use
9:08
the same logic here.
9:11
So you can just copy this here and paste
9:14
it. This is all the same code that we
9:16
are using here. Again we are inserting
9:20
we are getting the list of the
9:22
subscribers guys. You just getting the
9:25
same information and this time we need
9:27
to pass the third parameter guys which
9:29
is called as the page token property.
9:32
Page token and this this property is
9:36
needs to be in double quotes. So page
9:39
token guys we will be initializing it to
9:41
the next page token that we got.
9:44
So after this guys we will once again
9:47
check here.
9:50
After this we will make again make
9:56
a next page token to be result dot next
9:59
page token. After this guys we need to
10:04
push this into our array here. So we
10:07
will simply say dot dot dot result dot
10:10
items. That's it. This is all that we
10:13
need to do guys inside this. So
10:19
if you see here this while loop is now
10:22
ending here. After we do this this while
10:25
loop will end here inside this curly
10:26
bracket. That's all. Inside this while
10:28
loop you can see we are again fetching
10:30
the same information and this time we
10:32
are getting the page token. So we are
10:34
simply attaching this next page token.
10:36
So if now it becomes null here the while
10:40
loop will break. If it is not null then
10:42
again we will loop through. We will
10:44
again do the same process again and
10:46
again and push it inside the subs array
10:48
which is an empty array. By default it
10:50
contains this result dot items. And once
10:53
again we are appending it like this.
10:57
So now guys after getting the list of
10:59
subscribers inside our subscribers array
11:02
now the time has come to simply insert
11:04
this inside our spreadsheet.
11:08
So if you see here
11:13
we can simply insert it by the
11:16
spreadsheet. So there is a spreadsheet
11:18
app method and open it by the id. So we
11:20
have provided the ID which is inside
11:23
this variable spreadsheet
11:26
id
11:28
and then we can even get the sheet name
11:31
sheet one
11:34
SS dot get sheet by name and here we
11:37
will pass the sheet name constant
11:39
variable.
11:40
After this guys we will get the data
11:42
range property here and this time we
11:46
will get the get data range property.
11:50
After this guys, we will get the subs id
11:54
range
11:57
or this we we don't know we don't need
12:00
this. We will simply map
12:03
we will use the subs array here and we
12:06
will use the map method here. For each
12:08
subscribers what we need to do guys
12:10
inside this arrow function we need to
12:12
get the information. So first
12:13
information we will get is the snippet.
12:15
So this is subscribers dot subscriber
12:19
snippet. So after this we need to return
12:22
this information from it. The snippet we
12:25
need to return the snippet dot title and
12:28
snippet dot channel id and snippet and
12:32
also we need to attach dynamically which
12:35
is the channel URL. So the the syntax
12:39
remains the same for channel URL guys.
12:41
the starting syntax which is https
12:44
www.youtube.com
12:46
and after that / channel and then the
12:50
dynamic variable which is uh snippet dot
12:54
channel id. That's it.
13:01
So that's it guys. So
13:04
then we can even put a comma and
13:07
basically we can show the date and time
13:11
whenever they subscribe to the channel.
13:13
So subscribe snippet dot published that
13:17
that's it. So this will contain all this
13:20
information guys that I showed you early
13:23
on the table. It will return this
13:24
information. Now we simply need to
13:27
uh inside the if condition we just need
13:30
to check that if the values which is
13:33
obviously this map function return an
13:35
array guys. So we are simply getting the
13:37
length of that array which is
13:39
values.length if it is equal or if it is
13:42
greater than zero then we perfectly know
13:44
that there is some subscribers there.
13:47
So we need to load them inside the
13:49
screen.
13:53
Basically this is a logic guys which is
13:55
required in order to insert the
13:58
subscribers and show them inside Google
14:00
sheet. Let me paste it. You will see we
14:03
are starting from the
14:06
we calculating the number of rows and
14:08
this is the logic behind. So simply guys
14:12
now if I save this and now if I try to
14:15
run this.
14:18
So early on you need to grant permission
14:20
guys whenever you run for the very first
14:22
time you need to grant permission before
14:24
you are running it. So this will ask for
14:27
a simple review permission screen here
14:30
and you need to select your YouTube
14:33
channel here. Let me select my coding
14:35
channel and this is perfectly fine. This
14:37
is your own app that's why there is no
14:39
nothing to worry about. And simply you
14:42
can see this is a scopes out there.
14:44
Simply click allow. And now this will
14:49
execution started.
14:51
So basically in a few
14:54
time
14:56
it will embed all the you can see that
14:59
subscriber information is successfully
15:01
embedded inside the Google sheet. You
15:03
can see alongside with channel ID,
15:04
channel URL, date of time when they
15:07
subscribed to channel. So this is very
15:09
much useful for channel YouTube channel
15:11
owners guys. So if you're giving if you
15:14
are just doing giveaways, you need the
15:16
channel URL members. So in this way you
15:19
can do this process in Google appcript.
15:22
The all the source code is given in the
15:23
description of this video. Please hit
15:25
that like button, subscribe the channel
15:27
and I will be seeing you in the next
