Arthur Ferreira
Arthur Ferreira

Reputation: 321

Cannot create a spreadsheet file using Google Drive Android API

I'm currently trying to create a new Google Spreadsheet file using the Google Drive Android API. At the moment, this is the content of my ResultCallback class:

@Override
public void onResult(ContentsResult result) {
    if (!result.getStatus().isSuccess()) {
        // Handle error
        return;
    }

    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle("My Spreadsheet")
            .setMimeType("application/vnd.google-apps.spreadsheet").build();

    Drive.DriveApi.getRootFolder(mGoogleApiClient)
            .createFile(mGoogleApiClient, changeSet, result.getContents())
            .setResultCallback(fileCallback);
}

Every time I run the app I get the warning log "Upload failed HTTP status 400". However, if I change the MIME type to any non-Google service (eg. text/plain, application/vnd.ms-excel, etc.), the file is created successfully. Is this happening because I cannot create empty Google Docs files using the API?

Thank you.

Upvotes: 1

Views: 879

Answers (2)

jogo
jogo

Reputation: 91

I am also analyzing possibilities of integration Android client with Google Drive and apparently there is a way but not using the Drive API but Google Spreadsheets API directly to create and modify Google Spreadsheets.

Check this question

Upvotes: 0

lukiant-dev
lukiant-dev

Reputation: 51

Maybe the problem is that you are trying to upload Google spreadsheet without any body? Or maybe you should try to achieve what you want with pure Java SDK API?

Here is few links:
How do I upload file to google drive from android
https://developers.google.com/drive/android/create-file

Upvotes: 1

Related Questions