这种获取谷歌硬盘文件缩略图的方法对我来说一直很有效,但最近似乎停止了
我在网上找到的所有答案都表明这是因为thumbnailLink需要授权(eg)。但是,我正在使用授权访问令牌访问缩略图。我可以使用带有这些访问令牌的Drive API "Files: get"来获取文件信息,但是thumbnailLink返回404
print(http)
# <google_auth_httplib2.AuthorizedHttp object at 0x11561d0f0>
# An instance of google_auth_httplib2.AuthorizedHttp
url = 'https://www.googleapis.com/drive/v3/files/%s?fields=thumbnailLink' % file_id
response, content = http.request(url)
data = json.loads(content)
print(data['thumbnailLink'])
# https://docs.google.com/u//feeds/vt?gd=true&id=***fileID***&v=203&s=***&sz=s220
# Works ✓
response, content = http.request(data['thumbnailLink'])
print(response['status'])
# 404
# :(
同时给出404错误:
thumbnailLink + "&access_token=" + YOURTOKEN;
如建议的{a3}李>thumbnailLink
(以文件所有者身份登录到Google)李>thumbnailLink
-将/u//
替换为/u/0/
、/u/1/
、/u/2/
(当我以该用户身份打开驱动器时,URL为https://drive.google.com/drive/u/1/my-drive)有人知道获取谷歌硬盘缩略图文件的可靠方法吗
我相信你的目标如下
问题和解决方法:
在当前阶段,缩略图中的
404
情况似乎就是错误所在。这已经向谷歌问题追踪者报告Ref而且谷歌方面似乎已经众所周知了。不幸的是,我认为这是目前的直接答案。而且,我相信这个问题会在未来的更新中得到解决在这里,作为当前的解决方法,如何将其转换为PDF文件并检索缩略图?在这种情况下,可以使用缩略图链接。此解决方案的流程如下所示
当上述流转换为python脚本时,它将变成如下所示
示例脚本:
在使用此脚本之前,请设置访问令牌和文件ID。在本例中,为了使用简单脚本请求
multipart/form-data
,我使用了requests
库注:
https://www.googleapis.com/auth/drive
的作用域包含到您的访问令牌的作用域中。因为文件是上传的李>access_token=###
一起使用。因此,请使用访问令牌访问请求头Ref参考资料:
相关问题 更多 >
编程相关推荐