In the Apps Script G+ Community Scott Marquardt asked:
Youtube API question.
Argh, I can't find a single example of anything like this. With my current knowledge, I have a hard time inferring from the API reference documents alone, to Apps Script.
My goal is a script to add an item to a Youtube playlist. My intended workflow is a Google form to enter video IDs into a Google sheet, with a triggered script adding each new video ID to a hard-coded playlist.
I'm unashamedly panhandling here, on behalf of what would be a really valuable use case in a dozen of our special education schools.
I agree with Scott that the Apps Script Advanced Services documents (here’s YouTube) don’t give you much to go on. The solution is actually relatively simple once you get your head around the shape of the data required. So here is a form linked to this playlist (I’ll turn this off as soon as it starts getting spammed). In the spreadsheet receiving responses the Tools > Script editor has the following code (in the script you’ll see where you need to hard code the playlist you want to add videos to):
Update: Scott asked about adding notes/comments to playlist items and I've updated the code to do this to the gist
To get this working there are a couple of hoops to jump through. As the YouTube API is an Advanced Service and it must be enabled before use. For this project to do this you need to be in the Script Editor then:
- Click Resources > Advanced Google Services…
- Scroll down to YouTube Data API to turn it on then click the ‘Google Developers Console link:
- In the Google Developers Console find and turn on the YouTube API. After it’s enabled you can close the Console window
You can only interact with YouTube Channels the account authorised to run the script is the owner of (see related post by me on this).
The final step is to setup the script to trigger when the form is submitted. To do this while still in the Script Editor select Resources > Current project’s triggers and add a run addVideoToPlaylist event on form submit.
If you would prefer to not do all the code copy and pasting you can File > Make a copy of this sheet (you’ll still need to enable Advanced Services and the form submit.
There’s obviously lots more you could do with this script like putting submissions into a moderation queue but I’ll let you go and play with those ideas.
I was building an analytics dashboard today that collected data from various services including Google Anaytics and YouTube. Apps Script makes this very easy as highlighted in my previous post. An issue I encountered when I tried to access our YouTube channel reports is even though my account is attached to as a manager I was getting a ‘Forbidden’ error. Turning to the Channel Reports documentation I discovered:
channel==CHANNEL_ID – Set
CHANNEL_ID to the unique channel ID of the channel for which you are retrieving data. The user authorizing the request must be the owner of the channel.
As our YouTube channel is associated with our Google+ page you can’t log in to Google Drive with that account. I did notice however that when I added YouTube Analytics as an Advanced Apps Script service the authentication prompt gave an option of authenticating using our Google+ page.
The issue then is if you authenticate against the Google+ page you can’t get access to other services like Google Analytics. I thought of a couple of ways I might tackle this such as writing a separate Apps Script project that just got the YouTube Analytics data and wrote it to the spreadsheet I was working on. I’m not entirely sure how the permissions would work out on that. Instead my solution was to expose the YouTubeAnalytics.Reports.query in a separate Apps Script published as a web app. Setting this to run ‘anyone, even anonymously’ I could then use UrlFetchApp to get the data in my main script.
Here’s how I set it up. Below (or in this gist) the 'main' script is handling all the data read/write to sheet and a separate 'proxy' Apps Script project running the YouTube Analytics data collection.
Note: This technique exposes our YouTube Channel report to the world (barring security by obscurity). The method we are exposing is read only so we don’t have to worry about an injection.
Feels a bit hacky but can you see a better way of doing this?
Update 22/07/2014: Matias Molinas had the great suggestion of writing the results to a sheet which would avoid exposing your data. Jarom McDonald has also suggested using Google App Engine would give security and scalability à la superProxy
The 2013 New Year’s greetings, from the French advertising and public relations company Publicis Groupe by their CEO Maurice Lévy is making multiple appearances in my circles
When I saw it my immediate thought was how did they do it? In the official press release they say:
It’s just one of the many very human interpretations of the standard YouTube functionality taken for granted today.
Looking for YouTube player functionality left me scratching my head. Looking at the source gave a big clue:
… basically the entire video area including title and controls is an embedded iframe. This allows Publicis Groupe to create their own Flash based player with custom functionality for pause, play etc.
To get the iframe into their YouTube channel they used YouTube’s Custom tab settings which are available on Branded Channels.
Simple but very effective.
Via Doug Holton I spotted that there is a new YouTube beta feature to add multiple choice questions (MCQ) to your Youtube videos. Those who have already taken a course on Coursera (surely everyone has now ;), will know the video with MCQ is one of the staples. From the ‘Video Questions Editor Beta’ page it says:
This is an opt-in beta for a simple Video Questions Editor on YouTube. Through this editor you can setup multiple questions to be displayed on top of your video during playback that a viewer can answer.
How can I use this feature?
The editor itself can be found on the video edit page, on the edit bar. After you have added several questions and the users have viewed them, you can see a summary of the interaction your users had with them through the analytics page, within the Annotations section.
The feature represents work in progress, there is no plan for long-term support of the feature and may be removed at any time without prior notification. Your comments will help us improve and perfect the mixtures we're working on. So jump in, play around and send your feedback directly to the brains behind the scenes.
The page also includes a link to opt-in to the beta.
If you do when you go to edit one of your videos you’ll get a ‘Questions’ button
Clicking on this lets you enter your question:
Unfortunately when I click on save it hangs on ‘Your changes are being saved...’.
It’s a shame that this feature doesn’t work yet. It’s interesting to put this development into the context of Google’s recent open source release of Course Builder, which was used as the technology behind their Power Searching with Google online course (xMOOC). So is Google trying to rock the boat in the mass online education market?