I recently updated the Gradle plugin from version 3.4.2
to 3.5.0
.
The code to access the list of Drive files has stopped working.
I get: 403 Forbidden domain
": "usageLimits", "reason": "dailyLimitExceededUnreg", "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
if I use 3.4.2
it works perfectly again.
// Login
signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(new Scope(DriveScopes.DRIVE_FILE))
.build();
GoogleSignInClient client = GoogleSignIn.getClient(Backup.this, signInOptions);
startActivityForResult(client.getSignInIntent(), REQUEST_CODE_SIGN_IN);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if (requestCode == REQUEST_CODE_SIGN_IN) {
if (resultCode == Activity.RESULT_OK && resultData != null) {
handleSignInResult(resultData);
}
...
}
super.onActivityResult(requestCode, resultCode, resultData);
}
private void handleSignInResult(Intent result) {
GoogleSignIn.getSignedInAccountFromIntent(result)
.addOnSuccessListener(new OnSuccessListener<GoogleSignInAccount>() {
@Override
public void onSuccess(GoogleSignInAccount googleAccount) {
// Use the authenticated account to sign in to the Drive service.
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(Backup.this, Collections.singleton(DriveScopes.DRIVE_FILE));
credential.setSelectedAccount(googleAccount.getAccount());
Drive googleDriveService =
new Drive.Builder(
AndroidHttp.newCompatibleTransport(),
new GsonFactory(),
credential)
.setApplicationName("MyAPP")
.build();
mDriveServiceHelper = new BackupDriveServiceHelper(googleDriveService);
// get info
mDriveServiceHelper.readFileInfo()
.addOnSuccessListener(new OnSuccessListener<Bundle>() {
...
})
.addOnFailureListener(new OnFailureListener() {
...
});
...
}
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
public class BackupDriveServiceHelper {
...
public Task<Bundle> readFileInfo() {
return Tasks.call(mExecutor, new Callable<Bundle>() {
@Override
public Bundle call() throws Exception {
// Retrieve the metadata as a File object.
String pageToken = null;
do {
FileList result = mDriveService.files().list()
.setSpaces("drive")
.setFields("files(id, name, size, modifiedTime, description)")
.setPageToken(pageToken)
.execute(); // <<<<< error 403
...
pageToken = result.getNextPageToken();
} while (pageToken != null);
...
}
});
}
}