我的应用程序使用OAuth2服务帐户从用户的Google云端硬盘复制文件.我正在通过Java使用Google云端硬盘客户端API来获取所请求范围为" https://www.googleapis.com/auth/drive " 的云端硬盘对象.我可以复制Google Docs文档,但thumbnailLink不可检索.我收到403 Forbidden错误.我非常有信心这是Google方面的一个错误.如果我在我的代码中设置一个断点来获取403 Forbidden结果,我可以(当我正在复制Google Drive的用户登录时)使用thumbnailLink在我的浏览器中获取缩略图.
这是我正在使用的代码的重写代码片段,其中sourceFile是从中复制的com.google.api.services.drive.model.File,而sourceDrive是com.google.api.services.drive.Drive对象我上面提到的:
File newFile = new File(); newFile.setTitle( sourceFile.getTitle() ); newFile.setDescription( sourceFile.getDescription() ); newFile.setParents( sourceFile.getParents() ); File copiedFile = sourceDrive.files().copy( sourceFile.getId(), newFile ).execute(); String thumbnailLink = copiedFile.getThumbnailLink(); HttpRequest request = sourceDrive.getRequestFactory().buildGetRequest( new GenericUrl( thumbnailLink ) ); HttpResponse response = request.execute();
如上所述,request.execute()行由于返回403 Forbidden错误而产生异常.如果我在上面的代码片段的最后一行放置一个断点,我可以将thumbnailLink粘贴到我的浏览器中,该浏览器以正在复制其驱动器的用户身份登录并成功返回缩略图.