Home > Enterprise >  Chilkat VB.net Google Drive 404 using shared folderID
Chilkat VB.net Google Drive 404 using shared folderID

Time:03-14

Trying to get this working on shared Google Drive, I was able to get a 200 response initially but the folder was never written anywhere I could find. So I added the parent and now I am getting 404 error.

{
 "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

I see a lot of things buzzing around the answer but cannot seem to get this one. I saw adding supportsAllDrives=True, but was not sure where to add that....

CodePudding user response:

So, I needed to add the parent folder id of the shared folder

enter image description here

I needed to add these 2 lines for the file to be created on the shared drive.

enter image description here

  • Related