通过共享链接从Google云端硬盘获取文件 [英] Get file from Google Drive via shared link
问题描述
我正在制作类似在线日记本应用程序,它会从Google云端硬盘(通过共享链接)下载日记文件一次,并会在更改该文件时进行更新。请,任何人都可以指点我的一些指南如何做到这一点。我已经尝试从驱动器中固定文件,但我不明白接下来要做什么..
解决方案 从Google Drive下载文件:
要通过链接下载Google Drive文件,请尝试此操作(从本教程):
https://drive.google.com/uc?export=download&id=FILE_ID
只需将FILE_ID替换为在云端硬盘网址中找到的原始文件ID即可。
补充说明:
您可以使用 DRIVE REST API
要下载文件,一个授权的HTTP GET请求到文件的资源URL并包含查询参数alt = media。例如:
GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
Authorization:Bearer ya29.AHESVbXTUv5mHMo3RYfmS1YJonjzzdTOFZwvyOAUVhrs
下载文件需要用户至少读取权限。此外,您的应用程序必须获得允许读取文件内容的范围的授权。例如,使用drive.readonly.metadata范围的应用程序将无权下载文件内容。具有编辑权限的用户可以通过将viewersCanCopyContent字段设置为true来限制只读用户下载。
在Google云端硬盘中更新文件
使用PATCH向Google云端硬盘发出HTTP请求。 PATCH方法要求应用请求实体中描述的一组更改到由Request-URI标识的资源。需要注意的是:
- 参数
- 授权
- 请求正文
I'm making something like online journal app, that will download "journal file" from Google Drive (via shared link) once and will update that file if it changes. Please, can anyone point me to some guides how to do it. I already tried to pin file from drive, but I don't really understand what to do next..
Downloading Files from Google Drive:
To download a Google Drive file via link, try this (from this tutorial):
https://drive.google.com/uc?export=download&id=FILE_ID
Just replace the FILE_ID with the original fileID found in the Drive URL.
Additonal notes:
You can download files using the DRIVE REST API
To download files, you make an authorized HTTP GET request to the file's resource URL and include the query parameter alt=media. For example:
GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
Authorization: Bearer ya29.AHESVbXTUv5mHMo3RYfmS1YJonjzzdTOFZwvyOAUVhrs
Downloading the file requires the user to have at least read access. Additionally, your app must be authorized with a scope that allows reading of file content. For example, an app using the drive.readonly.metadata scope would not be authorized to download the file contents. Users with edit permission may restrict downloading by read-only users by setting the viewersCanCopyContent field to true.
Updating files in Google Drive
Make an HTTP Request to Google Drive using PATCH. The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI. Things to take note of are:
- Parameters
- Authorization
- Request Body
这篇关于通过共享链接从Google云端硬盘获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!