0

I want to save app database to gmail with the following tutorial :
Backup of Room Database files in Android | REST API v3

When I want to upload the database with the following code:

private void upload(){
    File storageFile = new File();
    storageFile.setParents(Collections.singletonList("appDataFolder"));
    storageFile.setName("classmanager");

    File storageFileShm = new File();
    storageFileShm.setParents(Collections.singletonList("appDataFolder"));
    storageFileShm.setName("classmanager-shm");

    File storageFileWal = new File();
    storageFileWal.setParents(Collections.singletonList("appDataFolder"));
    storageFileWal.setName("classmanager-wal");

    java.io.File filePath = new java.io.File(dbPath);
    java.io.File filePathShm = new java.io.File(dbPathShm);
    java.io.File filePathWal = new java.io.File(dbPathWal);
    FileContent mediaContent = new FileContent("",filePath);
    FileContent mediaContentShm = new FileContent("",filePathShm);
    FileContent mediaContentWal = new FileContent("",filePathWal);
    try {
        File file = googleDriveService.files().create(storageFile, mediaContent).execute();
        Log.i("TestGoogleDrive", "Filename: " + file.getName() + " File ID: " + file.getId());

        File fileShm = googleDriveService.files().create(storageFileShm, mediaContentShm).execute();
        Log.i("TestGoogleDrive", "FilenameShm: " + fileShm.getName() + " File IDShm: " + fileShm.getId());


        File fileWal = googleDriveService.files().create(storageFileWal, mediaContentWal).execute();
        Log.i("TestGoogleDrive", "FilenameWal: " + fileWal.getName() + " File IDWal: " + fileWal.getId());

    }
    catch(UserRecoverableAuthIOException e){
        Log.i("TestGoogleDrive"," UserRecoverableAuthIOException");
        startActivityForResult(e.getIntent(), 1);
    }
    catch(Exception e){
        Log.i("TestGoogleDrive"," Exception");
        e.printStackTrace();
        e.printStackTrace();
    }
}

But It didn't work and got below error :

2022-02-22 09:25:46.201 20037-26860/? I/TestGoogleDrive:  Exception
2022-02-22 09:25:46.201 20037-26860/? W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
2022-02-22 09:25:46.202 20037-26860/? W/System.err:     at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
2022-02-22 09:25:46.202 20037-26860/? W/System.err:     at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Nima Khalili
  • 360
  • 4
  • 20

0 Answers0