0

I want to be able to get Analytics Report of each video in a branded account.. I am following a tutorial on this website Link: https://mashe.hawksey.info/2017/10/getting-youtube-analytics-with-google-apps-script-when-you-get-authentication-loops/ In the tutorial, i provide a way to get and store Authorized token using "cGoa" Library.. My approach is to first get all the videos in the YoutUbe account and store them into an array, then get Analytics for each video with loop. But i am getting errors while running the code to retreive videos from the channel. Below is the Code i wanted to use to retrieve Videos. Note: I am Using YouTube Library Provided in the Tutorial i read from page link above

var goa = cGoa.GoaApp.createGoa('youtube-analytics',
                                  PropertiesService.getUserProperties())
                                  .execute();
   
  YouTube.setTokenService(function(){ return goa.getToken(); } );
  //YouTubeAnalytics.setTokenService(function(){ return goa.getToken(); });  
 
  var results = YouTube.channelsList('id,snippet,contentDetails,statistics', {mine: true});
  //Logger.log(results[0].contentDetails.relatedPlaylists.uploads);
  //Logger.log(results[0].id);
  var channelId = results[0].id;
  for(var i in results) {
    var item = results[i];
    // Get the playlist ID, which is nested in contentDetails, as described in the
    // Channel resource: https://developers.google.com/youtube/v3/docs/channels
    var playlistId = item.contentDetails.relatedPlaylists.uploads;
    var nextPageToken = '';
    var titleArray = [];
    var idArray = [];
    var reportArray = [];
    
    // This loop retrieves a set of playlist items and checks the nextPageToken in the
    // response to determine whether the list contains additional items. It repeats that process
    // until it has retrieved all of the items in the list.
    while (nextPageToken != null) {
      var playlistResponse = YouTube.playlistItemsList('snippet', {
        playlistId: playlistId,
        maxResults: 25,
        pageToken: nextPageToken
      });

      for (var j = 0; j < playlistResponse.items.length; j++) {
        var playlistItem = playlistResponse.items[j];
        //Logger.log('[%s] Title: %s',
                    //playlistItem.snippet.resourceId.videoId,
                   //playlistItem.snippet.title);
        titleArray[j] = playlistItem.snippet.title;
        idArray[j] = playlistItem.snippet.resourceId.videoId;
        var videoId = playlistItem.snippet.resourceId.videoId;
        reportArray[j] = runYoutubeAnalyticsReport(channelId , videoId)

      }
      //Browser.msgBox("hellon");
      nextPageToken = playlistResponse.nextPageToken;
    }
    create_cheet(idArray , titleArray , reportArray);
  }
}
When I run the code, this is the error i get
Error: { "error": { "errors": [ { "domain": "youtube.part", "reason": "unknownPart", "message": "snippet?pageToken=CBkQAA", "locationType": "parameter", "location": "part" } ], "code": 400, "message": "snippet?pageToken=CBkQAA" } } (line 83, file "Youtube", project "YouTube")

I have been struggling on this issue for over a week now.. Hope i will get solution to this issue.. I Highly Appreciate Your Help and Response. Thanks You!

Femikuye
  • 43
  • 6
  • Can you add any details like error problem encountered? [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask), [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) Show the community what you have tried. – abielita Nov 15 '18 at 14:03
  • I Have Updated my Question with hope that you would now have full understanding about my issue. Thanks.. – Femikuye Nov 23 '18 at 15:16

0 Answers0