如何将数据库上传到google gmail
我想使用以下教程将应用程序数据库保存到 gmail:
备份房间数据库文件在 Android 中 | REST API v3
当我想使用以下代码上传数据库时:
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();
}
}
但它不起作用并出现以下错误:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论