Reputation: 1448
I have This script that lists my favorite videos of youtube using Oauth and the YTB API v2.
Now I would like to do the same with the YTB DATA API V3 and who knows an easy step ahaed is the YTB ANALYTICS API V1.
So I was looking for the URL that would get me to the favorites in V3.
var URL = "https://www.googleapis.com/youtube/v3/"
instead of
//var URL = "http://gdata.youtube.com/feeds/api/users/default/favorites?v=2";
Is that there a way to do it like this with the DATA API v3?
Or is it only possible to reach to the simple data with the long URL request with the API KEY as in the github example of @Arun Nagarajan
var url = 'https://www.googleapis.com/youtube/v3/activities?'
+'part=snippet&channelId=UC_x5XG1OV2P6uZZ5FSM9Ttw&maxResults=20&publishedBefore=2013-02-25T00:00:00.0Z'
+'&key='+API_KEY;
Here is the part of the code that I would like to use with the YTB API v3.
//var URL = "http://gdata.youtube.com/feeds/api/users/default/favorites?v=2"; works
var URL = "https://www.googleapis.com/youtube/v3/" // cant find it
function getFavoriteVideos()
{
var data = UrlFetchApp.fetch(URL, googleOAuth_()).getContentText();
var xmlOutput = Xml.parse(data, false);
var favorites = xmlOutput.getElement().getElements('entry');
Logger.log("a" + favorites.length.toString())
var a = favorites.length.toString()
for(var i = 0; i < favorites.length; i++)
{
favorites[i].getElement('title').getText()
Logger.log(favorites[i].getElement('title').getText())
}
}
The authentication
var NAME = 'youtube';
var SCOPE = 'http://gdata.youtube.com';
function googleOAuth_() {
var oAuthConfig = UrlFetchApp.addOAuthService(NAME);
oAuthConfig.setRequestTokenUrl('https://www.google.com/accounts/OAuthGetRequestToken?scope='+SCOPE);
oAuthConfig.setAuthorizationUrl('https://www.google.com/accounts/OAuthAuthorizeToken');
oAuthConfig.setAccessTokenUrl('https://www.google.com/accounts/OAuthGetAccessToken');
oAuthConfig.setConsumerKey('anonymous');
oAuthConfig.setConsumerSecret('anonymous');
return {oAuthServiceName:NAME, oAuthUseToken:'always'};
}
Upvotes: 1
Views: 1527
Reputation: 847
The problem with utilizing the oAuthConfig class is that it's based on oAuth1 not oAuth2.
There is a request in at Google-Apps-Scirpt-Issues to upgrade to oAuth2: https://code.google.com/p/google-apps-script-issues/issues/detail?id=2580
I initially forgot to mention there is a posting in SO on using oAuth2 with GAS, Arun, in his response, posted a reference to an example he provides in GitHub: How to authorize with oauth 2.0 from appscript to Google APIs?
Upvotes: 2