1

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.

Arthur Ferreira
  • 311
  • 1
  • 6
  • 18

2 Answers2

1

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

Community
  • 1
  • 1
  • The problem is that I cannot add any content to the spreadsheet before actually saving it to the Drive. Hence, I think there should be a way to save a blank spreadsheet file using the API, right? I did not find anything in the documentation that says otherwise. – Arthur Ferreira Jul 15 '14 at 21:18
  • I'm almost sure that I'd be able to have it working using the pure Java Drive SDK. However, I'd really try to make sure I cannot accomplish this using the new API, or if this just not my fault. – Arthur Ferreira Jul 15 '14 at 21:21
  • I have the same problem. I've could upload a blank spreadsheet with Google Drive API the same way you did it. But something is wrong so this solution doesn´t seem to work anymore. However you can create and modify content once you get your spreadsheet in you Google Drive account. To do that you need to use [Google Spreadsheet API][1] – user1680435 Aug 30 '14 at 18:34
0

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

Community
  • 1
  • 1
jogo
  • 91
  • 1
  • 2