1
votes

I'm trying to write a script that gets all of the completed YouTube live streams from one of my channels that I manage and writes some stats (view counts, etc) to a Google Spreadsheet.

My Google account is a manager for a few Google+ pages, and some of those pages are associated with YouTube Channels. The pages "own" the channels, as far as I can tell.

I throw this in Code.gs:

function updateStats() {

  var liveEventsResponse = YouTube.LiveBroadcasts.list('snippet', {
      maxResults: 50,
      pageToken: nextPageToken
    });

  Logger.log(liveEventsResponse);

}

When I run a function on the script, I get this box:

YouTube Authorization Box

I click my Google+ page and get this:

YouTube Authorization Box 2

If I click "Allow" and authorize the script as my Google+ page, the box closes and everything looked like it worked. Once I try to run the function again, however, it pops up the same boxes and asks me again.

My question is: Can I use the YouTube API in Google Apps Script to get data from a YouTube Channel owned by a Google+ Page, or is that not supported?

Thanks!

1

1 Answers

0
votes

As mentioned in YouTube Service

The YouTube service allows you to use the YouTube Data API and YouTube Live Streaming API in Apps Script. This API gives users the ability to manage their videos, playlists, channels, and live events.

Please note that this is an advance service that must be enabled before use.

However, there are certain authorization requirements for requests to the Content ID API, which are different from the requirements for authorizing other Live Streaming API requests. As mentioned in the documentation, the following APIs have authorization requirements.

  • Calling the Data API

    The API request must be authorized by the Google Account that owns the broadcasting YouTube channel.

  • Calling the Content ID API

    The API request must be authorized by a Google Account that is linked to the content owner that owns the broadcasting YouTube channel.

Please go through the documentation for more information.