Google drive api Google Drive API V3:获取修订版的内容
Google Drive API从V2更改为V3,从响应中删除revision.items。这些项目有一个URL列表,是.txt、.pdf等格式的文件(我使用的是直接HTTP协议,没有包装)。 在V3中,似乎没有办法做到这一点。然而,有一个?alt=media参数,它应该返回一个文件,但我在尝试时遇到了403错误 有什么线索吗 A.谷歌文档 对于GoogleDocs,由于无法使用DriveAPIv3检索修订版文件,因此我使用新的解决方法对其进行了修改。新的解决方法是使用Drive API v2Google drive api Google Drive API V3:获取修订版的内容,google-drive-api,Google Drive Api,Google Drive API从V2更改为V3,从响应中删除revision.items。这些项目有一个URL列表,是.txt、.pdf等格式的文件(我使用的是直接HTTP协议,没有包装)。 在V3中,似乎没有办法做到这一点。然而,有一个?alt=media参数,它应该返回一个文件,但我在尝试时遇到了403错误 有什么线索吗 A.谷歌文档 对于GoogleDocs,由于无法使用DriveAPIv3检索修订版文件,因此我使用新的解决方法对其进行了修改。新的解决方法是使用Drive API v2d
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### FileID ###/revisions/### RevisionID ###?alt=media" \
-o outputfilename
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### RevisionID ###?alt=media" \
-o outputfilename
模式2:
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### FileID ###/revisions/### RevisionID ###?alt=media" \
-o outputfilename
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### RevisionID ###?alt=media" \
-o outputfilename
参考资料:目前在v3驱动器上似乎不可能 修订版API将适用于上述非谷歌文档/幻灯片/工作表(二进制文件)。对于原生google docs文件,如果您尝试使用它,它将抱怨使用导出端点(file/id/export)。尝试导出端点会导致以下错误:
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidParameter",
"message": "Invalid field selection revisions=11175",
"locationType": "parameter",
"location": "fields"
}
],
"code": 400,
"message": "Invalid field selection revisions=11175"
}
我尝试了“rev”、“revision”、“revision”等字段,但运气不佳。
我在这里打开了一个用于处理OAUTH2任务的特性请求
然后我添加了这个函数来进行驱动器调用。exportLinks是否为空并不重要;只需构建如下URL
private async Task GetRevisionRedirect(string accessToken, string fileId, string revId)
{
Log("Making API Call to get revision binary stream...");
// builds the request
string userinfoRequestUri = "https://docs.google.com/feeds/download/documents/export/Export?id=" + fileId + "&revision=" + revId + "&exportFormat=docx";
// sends the request
HttpWebRequest userinfoRequest = (HttpWebRequest)WebRequest.Create(userinfoRequestUri);
userinfoRequest.Method = "GET";
userinfoRequest.Headers.Add(string.Format("Authorization: Bearer {0}", accessToken));
userinfoRequest.ContentType = "application/x-www-form-urlencoded";
userinfoRequest.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
// gets the response
WebResponse userinfoResponse = await userinfoRequest.GetResponseAsync();
using (StreamReader userinfoResponseReader = new StreamReader(userinfoResponse.GetResponseStream()))
{
// reads response body
System.IO.Stream streamDoc = userinfoResponseReader.BaseStream;
var fileStream = File.Create("d:\\test.docx");
streamDoc.CopyTo(fileStream);
fileStream.Flush();
fileStream.Close();
}
}
在没有用户交互的情况下,您打算如何对用户进行身份验证,或允许他授予对其资源的访问权限?这不再有效:“错误”:{“错误”:[{“域”:“全局”,“原因”:“invalidParameter”,“消息”:“无效字段选择修订=9598”,“位置类型”:“参数”,“位置”:“字段”}],“代码”:400,“消息”:“无效字段选择修订版=9598”}@Dexter Haslem感谢您的报告。你的信息对我有好处。幸运的是,在我的环境中,错误还没有发生,我可以在我的环境中下载修订文件。但最近的更新似乎改变了一些谷歌API。实际上,最近,我注意到它不再能够下载容器绑定脚本。所以这个方法在不久的将来可能会被修改。更新了我的答案。虽然我不认为这是最好的,但我想把它作为暂时的解决办法。我得到的印象是他们故意删除了v3上的修订,所以这可能是我们能做的最好的了