我做了以下
var NAME = 'youtube';
var SCOPE = 'http://gdata.youtube.com';
//var URL = "https://picasaweb.google.com/data/feed/api/user/default";
var URL = "http://gdata.youtube.com/feeds/api/users/default/favorites?v=2";
function doGet(e) {
var app = UiApp.createApplication().setTitle("youtube");
var data = UrlFetchApp.fetch(URL, googleOAuth_()).getContentText();
var xmlOutput = Xml.parse(data, false);
var favorites = xmlOutput.getElement().getElements('entry');
app.add(app.createLabel(favorites.length.toString()))
for(var i = 0; i < favorites.length; i++){
app.add(app.createLabel(favorites[i].getElement('title').getText()))
//var testf = favorites[i].getElement('http://gdata.youtube.com/schemas/2007#favorite','href');
}
return app;
}
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'};
}
要获得最喜欢的视频的标题,它可以正常工作
但我找不到如何获取最喜欢视频的网址的方式
我在哪里可以找到文档?
而不是另一个问题,当我尝试执行脚本时
与另一个谷歌帐户,它仍然给出错误:
执行该操作需要授权
googleOAuth_()
funcion不是在照顾它吗?
答案 0 :(得分:1)
这是一个有效的解决方案......
(编辑:更好的代码)
var NAME = 'youtube';
var SCOPE = 'http://gdata.youtube.com';
//var URL = "https://picasaweb.google.com/data/feed/api/user/default";
var URL = "http://gdata.youtube.com/feeds/api/users/default/favorites?v=2";
function doGet(e) {
var app = UiApp.createApplication().setTitle("youtube").setStyleAttribute('padding','20');
var data = UrlFetchApp.fetch(URL, googleOAuth_()).getContentText();
var xmlOutput = Xml.parse(data, true);
var favorites = xmlOutput.getElement().getElements('entry');
app.add(app.createLabel('YouTube favourites entries : '+favorites.length.toString()).setStyleAttribute('padding','10'))
var table = app.createFlexTable().setWidth('400').setStyleAttribute('background', '#ffffdd')
for(var i = 0; i < favorites.length; i++){
if(favorites[i].getElement('link')){
var url = favorites[i].getElement('link').getAttribute('href').getValue();}
if(favorites[i].getElement('title')){
var Title = favorites[i].getElement('title').getText()}
table.setText(i, 0, 'Clip Title : '+Title).setWidget(i, 1, app.createAnchor('link', url)).setBorderWidth(1)
}
app.add(table)
return app;
}