该演示不使用服务帐户。
我将演示如何下载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进行获取对于测试目的而言更为容易。



