gpt4 book ai didi

android - 如果我升级到 Gradle Plugin v3.5.0,Google Drive API 403 Forbidden 错误

转载 作者:行者123 更新时间:2023-12-03 14:16:52 26 4
gpt4 key购买 nike

我最近从版本 3.4.2 更新了 Gradle 插件至3.5.0 .
访问云端硬盘文件列表的代码已停止工作。
我得到:403 Forbidden domain ": "usageLimits", "reason": "dailyLimitExceededUnreg", "message": "未验证使用的每日限制已超过。继续使用需要注册。”
如果我使用 3.4.2它再次完美运行。

// 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);
...
}
});
}
}

最佳答案

我发现在针对 Android 8 (API27) 时,如果我将它添加到项目 gradle.properties 中,我可以让 Google Drive 与 Gradle 3.5.0 一起使用

android.enableD8=false

但是,在针对 Android 9 (API 28) 并将 android.support.* 替换为 androidx.* 之后,我收到以下警告:
The option 'android.enableD8' is deprecated and should not be used anymore. 

问题又回来了。在我看来是 D8 DEX 编译器导致了问题,但它不能再被禁用?

我已经提交了 D8 的错误报告
https://issuetracker.google.com/issues/140882055

更新:Google 建议的解决方案确实有效:将其添加到 proguard-rules.pro 后,Google Drive 可与 Gradle 5.4.1 和 Plugin 3.5.0 一起使用
-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}

关于android - 如果我升级到 Gradle Plugin v3.5.0,Google Drive API 403 Forbidden 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57626028/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com