Google云端硬盘中的JSON文件列表 [英] JSON list of files in Google Drive

查看:267
本文介绍了Google云端硬盘中的JSON文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码片段,其中包含PICASA公共相册中的图片列表并构建滑块中使用的列表。简化代码如下所示:

  var usrID =555555555555555555555; 
var albID =5555555555555555555;
$ .getJSON(
https://picasaweb.google.com/data/feed/base/user/\"+usrID+\"/albumid/\"+albID+\"?alt=json&kind=photo& ; hl = en_US& callback =?,
function(data){
var picAlbumLst ='< ul id =slider>';
$ .each(data.feed .entry,function(i,element){
var picUrl = element [media $ group] [media $ thumbnail] [0] .url;
picAlbumLst + =(
'< li style =text-align:center>'+
'< img src =''+ picUrl +'/>'+
'< / li>'
);
});
picAlbumLst + =< / ul> \\\
;
...
});

我在考虑将我的照片从Picasa移至Google云端硬盘。有没有办法提出类似于我的旧版PICASA的请求,以便从Google Drive(匿名用户)获取网址?语法越接近,端口就越容易(我把它放在了这个地方)。

解决方案

以前很多次,我发布了一个问题,因为我懒得更难处理它。但我终于设法解决它。因此,以下是Google Drive解决方案:



1 /执行所有OAuth 2.0舞蹈以访问文件夹[IMAGE_FOLDER_ID]。即使该文件夹是公开的,该应用也必须经过认证/授权。

2 /不要忘记为Google云端硬盘服务加载API b
$ b


gapi.client.load('drive','v2',makeRequestCB)

...这里是循环来检索文件的URL

 函数makeRequestCB(){
'gapi.client.drive.files.list({$ b $ q':'[IMAGE_FOLDER_ID]在父母',
'字段'中:'items / id'
})。对于(i = 0; i< resp.items.length; i ++){$ b}执行(function(resp){
var picAlbumLst ='< ul id =slider>'; $ b var id = resp.items [i] .id;
picAlbumLst + =('< li>< img src =https://docs.google.com/uc?id='+id+ '; />< / li>');
}
picAlbumLst + =< / ul> \\\
;
});
}

希望它有帮助。


I have a code snippet that takes a list of pictures in PICASA public album and constructs a list used in slider. The simplified code looks like this:

var usrID = "555555555555555555555";
var albID = "5555555555555555555";
$.getJSON(
"https://picasaweb.google.com/data/feed/base/user/"+usrID+"/albumid/"+albID+"?alt=json&kind=photo&hl=en_US&callback=?",
function(data) {         
  var picAlbumLst = '<ul id="slider">';
  $.each(data.feed.entry, function(i, element) {
    var picUrl = element["media$group"]["media$thumbnail"][0].url;
    picAlbumLst += ( 
    '<li style="text-align:center">'+
    '  <img src="'+picUrl+'"/>'+
    '</li>'
    );
  });
  picAlbumLst += "</ul>\n";
  ...
});

I am thinking about moving my pictures from Picasa to Google Drive. Is there a way to make a request similar to my old PICASA one in order to get the URLs from Google Drive (anonymous user)? The closer the syntax, the easier the port would be (I have it all over the place).

解决方案

As many times before, I posted a question because I was too lazy to work on it harder. But I managed to resolve it in the end. So, here is the Google Drive solution:

1/ perform all the "OAuth 2.0" dances in order to gain access to the folder [IMAGE_FOLDER_ID]. The app has to be authenticated/authorized even if the folder is public.

2/ don't forget to load the API for the Google Drive service

gapi.client.load('drive', 'v2', makeRequestCB)

... and here's the loop to retrieve the file URLs

function makeRequestCB() {
  gapi.client.drive.files.list({
    'q': '"[IMAGE_FOLDER_ID]" in parents',
    'fields' : 'items/id'      
  }).execute(function(resp) {
    var picAlbumLst = '<ul id="slider">';
    for (i=0; i<resp.items.length; i++) {
      var id = resp.items[i].id;
      picAlbumLst += ('<li><img src="https://docs.google.com/uc?id='+id+'"/></li>');
    }
    picAlbumLst += "</ul>\n";
  });
}

Hope it helps.

这篇关于Google云端硬盘中的JSON文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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