2

When I'm using Youtube.Playlists.list in Google App script, I'm having an error that says "ReferenceError: "Youtube" is not defined". I enabled Youtube Analytics API and Youtube Data API but the error still appears. May I know how can I make this work?

function myFunction() {

  var playlistResponse = Youtube.Playlists.list('snippet',{
    mine: true,
        maxResults: 30,
        pageToken: nextPageToken
      });

  for (var x = 0; x < playlistResponse.items.length; x++)
      {
      var playlistItem = playlistResponse.items[x];
      var playlistId = playlistResponse.items.id;
      var playlistTitle = playlistResponse.items.snippet;

        Logger.log(playlistTitle);
        Logger.log(playlistId);
      }
}
Aldrin
  • 756
  • 6
  • 18
  • Did you go into the Google.Developers Console, and enable the YouTube API there also? If you didn't do that, it won't work. You need to enable the advanced service in TWO places. Inside Apps Script, *and* in the Google Developers Console. – Alan Wells May 18 '15 at 16:55

1 Answers1

0

All you need to do is change the lower case letter "t" to upper case:

var playlistResponse = Youtube.Playlists.list('snippet',{

Change to:

YouTube

It's case sensitive:

Alan Wells
  • 30,746
  • 15
  • 104
  • 152
  • HAHA I didn't notice that. Thank you! – Aldrin May 19 '15 at 08:43
  • I have the same problem. And I am using `YouTube`. But still it occurs. What's the problem? Should I import or enable some setting? – c-an Sep 18 '20 at 13:40
  • If you bring up the context menu with "Ctrl + Spacebar" does "YouTube" appear in the list? If not, the API is probably not enabled. – Alan Wells Sep 18 '20 at 14:24