Fragments: Accessing YouTube Account Data in Google Spreadsheets via OAuth

If you’re running a Youtube account, how might you collect Insights data for all your videos as spreadsheet entries that can be used in the preparation of reports about your social media effectiveness?

One way might be to go to each video in turn and download the separate CSV data files created for each video. Alternatively, you can grab the data via the YouTube/GData API (

I haven’t actually got round to getting any data out of my YouTube account and into a Google spreadsheet yet, but I have dome the first step, which is to set up the authentication using OAuth. Here’s the Google Apps script I used…

function youtube(){
  // Setup OAuthServiceConfig
  var oAuthConfig = UrlFetchApp.addOAuthService("youtube");

  // Setup optional parameters to point request at OAuthConfigService.  The "twitter"
  // value matches the argument to "addOAuthService" above.
  var options =
      "oAuthServiceName" : "youtube",
      "oAuthUseToken" : "always"

  var result = UrlFetchApp.fetch("", options);
  var o  = Utilities.jsonParse(result.getContentText());

[Gist here:]

The first time you run the script, it should request access from your YouTube account…

The next step is to work out what to pull from Youtube, and how to actually store it in the spreadsheet…

PS a couple more Youtube snippets of interest:
YouTube documentation wizard: customise your YouTube API documentation view
interactive YouTube API explorer