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.
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.
Comments