Error copying a file Google Drive SDK

Pelayo Gálvez

From Yesterday, in a code not changed for a couple of months, we get an error copying a file with Java Drive API.

We use the method:

service.files().copy(originalID, copiedFile).execute();

and get:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 OK
{
  "code" : 500,
  "errors" : [ {
    "domain" : "global",
    "message" : "Internal Error",
    "reason" : "internalError"
  } ],
  "message" : "Internal Error"
}

The complete code is:

public File copiarArchivo(Drive service, String originalID, String tituloCopia) {
        File copiedFile = new File();
        copiedFile.setTitle(tituloCopia);

        try {
            return service.files().copy(originalID, copiedFile).execute();
        } catch (IOException e) {
            System.out.println("Un error ocurrio: " + e);
        }

        return null;
      }

Drive service is initialized and we have an OriginalID that's not null.

Pelayo

You seem to be using the old KeyID used by the Spreadsheets API. That ID is no longer allowed while copying a file using the Drive API. You need to get that new FileID and use it in the copy sentence instead of the old one.

You can get that new ID following this example:

public String getNewFileID(Drive service, String oldSpreadsheetsKeyID){
   File file = service.files().get(oldSpreadsheetsKeyID).execute()
   String alternateLink = file.getAlternateLink();

   String[] aux1 = alternateLink.split("/spreadsheets/d/");         
   String[] aux2 = aux1[1].split("/edit?");

   String newFileID = aux2[0];

   return newFileID;
}

This will recover the ID from the complete URL. It may be a more efficient way to split the URL though. You can use this ID to make the copy.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error copying a file Google Drive SDK

From Dev

Delete file from Google Drive using Google Drive API SDK

From Dev

Google Drive SDK - How to get the folder that a file is in?

From Dev

Google Drive SDK JavaScript 404 Error

From Dev

Is there a way to upload file to Google Drive from InputStream in Drive SDK?

From Dev

Using Google Drive SDK to grant another Drive App authorization to file?

From Dev

Is there a way to upload file to Google Drive from InputStream in Drive SDK?

From Dev

Why do I get a error 400 trying to insert a CSV file with Google Drive SDK?

From Dev

OutOfMemory Error in downloading file from Google Drive using Java SDK API

From Dev

File not found error Google Drive API

From Dev

Google Drive SDK: I want to update a file, not create new one

From Dev

Remove a file shared with me using Google Drive SDK

From Dev

Remove a file shared with me using Google Drive SDK

From Dev

How to get the file URL uploaded in google drive SDK using php

From Dev

Google Drive SDK: I want to update a file, not create new one

From Dev

How to upload a file to google drive folder using android google drive sdk

From Java

Copying an Excel file from Google Drive to a newly created Folder using Script Editor

From Dev

Robo-Copying files between google file stream and a network drive with a windows task scheduler gets “Access Denied”

From Dev

Copying Google Drive folder to new computer

From Dev

Google Drive API/SDK TransferOwnership

From Dev

Google Drive SDK and Unicode filenames

From Dev

Google Drive File Picker random sign-in error

From Dev

Error 403 Forbidden while trying to download file from Google Drive

From Dev

Error running sample code to upload a file to google drive

From Dev

Google Drive SDK, fetching data on when the file was shared and when the file was last accessed

From Dev

Copy file on Google Drive

From Dev

DirectoryNotFoundException error while copying the file

From Dev

Error copying file in mounted usb

From Dev

Google Drive error on import

Related Related

  1. 1

    Error copying a file Google Drive SDK

  2. 2

    Delete file from Google Drive using Google Drive API SDK

  3. 3

    Google Drive SDK - How to get the folder that a file is in?

  4. 4

    Google Drive SDK JavaScript 404 Error

  5. 5

    Is there a way to upload file to Google Drive from InputStream in Drive SDK?

  6. 6

    Using Google Drive SDK to grant another Drive App authorization to file?

  7. 7

    Is there a way to upload file to Google Drive from InputStream in Drive SDK?

  8. 8

    Why do I get a error 400 trying to insert a CSV file with Google Drive SDK?

  9. 9

    OutOfMemory Error in downloading file from Google Drive using Java SDK API

  10. 10

    File not found error Google Drive API

  11. 11

    Google Drive SDK: I want to update a file, not create new one

  12. 12

    Remove a file shared with me using Google Drive SDK

  13. 13

    Remove a file shared with me using Google Drive SDK

  14. 14

    How to get the file URL uploaded in google drive SDK using php

  15. 15

    Google Drive SDK: I want to update a file, not create new one

  16. 16

    How to upload a file to google drive folder using android google drive sdk

  17. 17

    Copying an Excel file from Google Drive to a newly created Folder using Script Editor

  18. 18

    Robo-Copying files between google file stream and a network drive with a windows task scheduler gets “Access Denied”

  19. 19

    Copying Google Drive folder to new computer

  20. 20

    Google Drive API/SDK TransferOwnership

  21. 21

    Google Drive SDK and Unicode filenames

  22. 22

    Google Drive File Picker random sign-in error

  23. 23

    Error 403 Forbidden while trying to download file from Google Drive

  24. 24

    Error running sample code to upload a file to google drive

  25. 25

    Google Drive SDK, fetching data on when the file was shared and when the file was last accessed

  26. 26

    Copy file on Google Drive

  27. 27

    DirectoryNotFoundException error while copying the file

  28. 28

    Error copying file in mounted usb

  29. 29

    Google Drive error on import

HotTag

Archive