0
votes

I am trying to download a file from the drive using google drive api

Steps to reproduce : Step 1: Click on :https://developers.google.com/drive/v3/reference/files/export#try-it Step 2: I have provided fileid and mimetype I gave fileid and mime type as "application/vnd.google-apps.spreadsheet" and click on execute.i got this error: "code":403, "message":"Export requires alt=media to download the exported content."

public static void downloadFile(Drive service,String fileId) throws IOException{
        OutputStream outputStream = new ByteArrayOutputStream();
        //OutputStream outputStream = new FileOutputStream("/Users/xxxxx/Downloads/driveFile.xls");
        //service.get 
        service.files().export(fileId,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
        .executeMediaAndDownloadTo(outputStream);
    }
1
mmm, your question is not clear ☹YCF_L
I have used googleapis.com/drive/v3/files{fileid}/export to download a file .i gave input parameters file ID and mime type.i got response as bad requestSuvarna Lakshmi Godavarthy
and where is your code?YCF_L
I have used this link developers.google.com/drive/v3/reference/files/export#try-it .From here i am getting 403 error code . And here is my code , from the code also I am getting 403 error code . How do I paste the code, as it is not accepting whole code here because of it exceeds the limitSuvarna Lakshmi Godavarthy
@SuvarnaLakshmiGodavarthy, just edit your question to add your code.RealHowTo

1 Answers

0
votes

Based on the error you are getting...

https://developers.google.com/drive/v3/web/manage-downloads

Try adding "?alt=media" to your GET request. My guess is you are missing something in the input parameters or possibly do not have access to the media (not logged in maybe?). I can't help more without seeing the actual code you are attempting to call, or the request you are making.