有没有办法获得文件列表而不使用公共托管的Goolge Drive文件夹的授权?
示例文件夹:https://googledrive.com/host/0B1Nmfb7VDM6jNnhjWk9CdU9ueHc/
我想使用该文件夹来托管我将在其他网站上的图库中显示的图像.
小智 17
好的有一种方法,它非常简单,只需要一些设置.我们需要获取可以返回JSONP的Google云端硬盘URL,然后针对它运行请求.
生成公共URL.请访问:https: //developers.google.com/apis-explorer/?hl = en_GB#p/drive/v3/drive.files.list
在"q"字段中输入以下内容:
'{your_public_folder_id}' in parents
Run Code Online (Sandbox Code Playgroud)
单击按钮下方的"不使用OAuth执行"链接.
您现在应该看到下面列出的所有文件.它还会向您显示GET请求.这是您需要的URL.
复制请求URL.类似于:https://www.googleapis.com/drive/v3/files? q = '{your_public_folder_id}'+ in + parents&key = {YOUR_API_KEY}
现在,您需要生成API密钥.转到Google控制台:https://console.developers.google.com/ 在左侧菜单中选择"凭据".点击"创建凭据",然后选择API密钥.单击"浏览器键"复制生成键.
你现在可以这样做:
var api_key = '{YOUR_API_KEY}';
var folderId = '{your_public_folder_id}';
var url = "https://www.googleapis.com/drive/v3/files?q='" + folderId + "'+in+parents&key=" + api_key;
var promise = $.getJSON( url, function( data, status){
// on success
});
promise.done(function( data ){
// do something with the data
}).fail(function(){
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5106 次 |
| 最近记录: |