Chilkat VB.net Google 驱动器 404 使用共享文件夹 ID
Chilkat VB.net Google Drive 404 using shared folderID
试图让它在共享 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
,但不确定在哪里添加....
所以,我需要添加共享文件夹的父文件夹ID
我需要为要在共享驱动器上创建的文件添加这两行。
试图让它在共享 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
,但不确定在哪里添加....
所以,我需要添加共享文件夹的父文件夹ID
我需要为要在共享驱动器上创建的文件添加这两行。