栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Java中的Google Drive API库强制从Google Team Drive下载文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Java中的Google Drive API库强制从Google Team Drive下载文件

该演示不使用服务帐户。

我将演示如何下载Team驱动器文件,并希望它可以使您对项目有深入的了解。

该代码的基础来自Drive API Java
Quickstart

public static void main(String... args) throws IOException, GeneralSecurityException {        // Build a new authorized API client service.        final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();        Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))     .setApplicationName(APPLICATION_NAME)     .build();       //this is what you're looking for - a way to download a file using 'webContentlink'        try {Desktop desktop = java.awt.Desktop.getDesktop();   //place your webContentlink in the oURL variable   URI oURL = new URI("https://drive.google.com/a/google.com/uc?id=YOUR_FILE_ID&export=download");   desktop.browse(oURL);        } catch (Exception e) { e.printStackTrace();        }}

执行后,该程序将打开一个空白浏览器窗口,并将文件下载到您的计算机。

我生成的方式

webContentlink
只是使用Files.get Try-
it,并确保将其设置
supportsTeamDrives
true
,同时将
fields
参数设置为,
webContentlink
以便它仅返回该值。

当然,您始终可以以

files.get
编程方式使用Java 来进行获取,
webContentlink
但是
webContentlink
使用Try-
it进行获取对于测试目的而言更为容易。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/516434.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号