【发布时间】:2022-03-11 05:30:24
【问题描述】:
尝试在共享的 Google 云端硬盘上运行此功能时,我最初能够获得 200 个响应,但该文件夹从未写入任何我能找到的地方。所以我添加了父级,现在我收到 404 错误。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found: [FileId].",
"locationType": "parameter",
"location": "fileId"
}
],
"code": 404,
"message": "File not found: [FileId]."
}
}
Dim gAuth As New Chilkat.AuthGoogle
gAuth.AccessToken = GetGoogleAccessToken()
Dim rest As New Chilkat.Rest
' Connect using TLS.
Dim bAutoReconnect As Boolean = True
success = rest.Connect("www.googleapis.com", 443, True, bAutoReconnect)
' Provide the authentication credentials (i.e. the access token)
rest.SetAuthGoogle(gAuth)
' A multipart upload to Google Drive needs a multipart/related Content-Type
rest.AddHeader("Content-Type", "multipart/related")
' Specify each part of the request.
' The 1st part is JSON with information about the folder.
rest.PartSelector = "1"
rest.AddHeader("Content-Type", "application/json; charset=UTF-8")
Dim json As New Chilkat.JsonObject
json.AppendString("name", fFolderName)
json.AppendString("description", "A folder to contain test files.")
json.AppendString("mimeType", "application/vnd.google-apps.folder")
Dim folderId As String = "[folderId confirmed to be working]"
Dim parents As Chilkat.JsonArray = json.AppendArray("parents")
parents.AddStringAt(-1, folderId)
rest.SetMultipartBodyString(json.Emit())
' The 2nd part would be the file content.
' Since this is a folder, skip the 2nd part entirely and go straight to the upload..
Dim jsonResponse As String = rest.FullRequestMultipart("POST", "/upload/drive/v3/files?uploadType=multipart")
If (rest.LastMethodSuccess <> True) Then
Console.WriteLine(rest.LastErrorText)
Return False
Exit Function
End If
' A successful response will have a status code equal to 200.
If (rest.ResponseStatusCode <> 200) Then
Console.WriteLine("response status code = " & rest.ResponseStatusCode)
Console.WriteLine("response status text = " & rest.ResponseStatusText)
Console.WriteLine("response header: " & rest.ResponseHeader)
Console.WriteLine("response JSON: " & jsonResponse)
Return False
Exit Function
End If
我看到很多事情围绕着答案嗡嗡作响,但似乎无法得到这个答案。我看到添加了supportsAllDrives=True,但不知道在哪里添加......
【问题讨论】:
-
您有什么理由不使用 google .net 客户端库?找不到文件意味着您无权访问该文件或它不存在。
-
继承的应用程序需要保留一段时间。我正在使用谷歌服务帐户,并将其添加到根共享驱动器的共享中。我通过查看 URL 并获取最后一块获得了父文件夹 ID。这是获得它的正确方法吗?
-
@DaImTo 在阅读您最初的问题并进行反思时,我并不反对使用 .net 客户端库。你能指出我在 VB.NET 中使用它的正确方向吗?这是我无法更改的应用程序部分。
-
我很想看看您如何在不使用客户端库的情况下自行管理服务帐户身份验证。您是否通过 google drive web 应用与服务帐户共享文件?
-
我明白了。我会发布答案。 @DaImTo 建议 file.list 帮助我弄清楚我需要添加一些查询参数。查看答案。
标签: vb.net google-drive-api chilkat