我想通过Google Drive API将文件夹保存到Google Drive。
首先我去Google控制台,通过生成sha-1key来获取clientId 用于该项目
我还有将Firebase项目链接到项目中。
我收到了GoogleAuthIOException。
我的代码在这里
try {
//CODE TO CHECK FOLDER AVAILABILITY IN GOOGLE DRIVE
do {
FileList result = service.files().list()
.setQ("mimeType='application/vnd.google-apps.folder'")
.setSpaces("drive")
.setFields("nextPageToken, files(id, name)")
.setQ("trashed = false")
.execute();
for (com.google.api.services.drive.model.File file : result.getFiles()) {
fnam = file.getName().toString();
allFiles.add(fnam);
if (fnam.equals("com.package.name")) {
favail = true;
foldid = file.getId();
SharedPreferences.Editor edit = settings.edit();
edit.putString("GoogleDrive", "" + file.getId());
edit.commit();
break;
}
System.out.printf("Found file: %s (%s)\n",
file.getName(), file.getId());
}
pageToken = result.getNextPageToken();
} while (pageToken != null);
// IF NOT ANY FOLDER NAMED IS NOT FOUND THEN THIS CODE WILL CREATE A NEW FOLDER.
if (!favail) {
com.google.api.services.drive.model.File fileMetadata = new com.google.api.services.drive.model.File();
fileMetadata.setName("foloername");
fileMetadata.setMimeType("application/vnd.google-apps.folder");
if (foldid.equals("")) {
com.google.api.services.drive.model.File file = service.files().create(fileMetadata)
.setFields("id")
.execute();
foldid = file.getId();
SharedPreferences.Editor edit = settings.edit();
edit.putString("GoogleDrive", "" + file.getId());
edit.commit();
}
}
}catch (Exception e){
///////////////I got execption
here//////////////////////////////////
Log.d("driver",e.toString());
}
09-10 16:13:28.685 22974-25682 / Packageagename D /驱动程序:
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException