无法使用Google Drive API获取缩略图

 mobiledu2502857673 发布于 2023-01-16 09:02

我的应用程序使用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粘贴到我的浏览器中,该浏览器以正在复制其驱动器的用户身份登录并成功返回缩略图.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有