如何获得YouTube的最爱网址 [英] How to get the youtube favorites url

查看:133
本文介绍了如何获得YouTube的最爱网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了以下内容:

  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;

函数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 /模式/ 2007#最喜欢的, 'HREF');
}

返回应用;
}

函数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'};
}

要获得最喜欢的视频的标题, $ b但我无法找到如何到达最喜欢视频的网址。

我可以在哪里找到该文档?



另一个问题是,当我尝试使用另一个Google帐户执行脚本
时,它仍然会出现错误:

授权是执行该操作所必需的行动



googleOAuth _() funcion会照顾那个吗?

解决方案

这是一个可行的解决方案...

<更好的代码)

  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;
$ b函数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收藏夹条目:'+ 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;
}


I made the following

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'};
}

To get the title of the favorite videos it works fine
But I can´t find the way how to get to the url of the favorite video.
where can I find that in the documentation?

And than another question, when I try to execute the script
with another google account it still gives the error:
Authorization is required to perform that action

Isn´t the googleOAuth_() funcion taking care of that?

解决方案

Here is a working solution...

(EDIT : better code)

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;
} 

这篇关于如何获得YouTube的最爱网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆