Android App with Google Drive API stucks after choosing an account. Why?

我们两清 提交于 2021-02-17 03:36:32

问题


I'm trying to understand how I can integrate Google Drive API in my Android App(using Android Studio). I have tried the example app that I found here(https://github.com/googleworkspace/android-samples/tree/master/drive/deprecation) but after Google API console configuration my app stucks in an infinite loop when I choose an Account. Why? Where is the problem? I tried also with this(https://youtu.be/5bSEIQYJzKs) tutorial but I have the same problem. Here my build.gradle specific lines:

implementation "androidx.multidex:multidex:2.0.1"
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation ('com.google.apis:google-api-services-drive:v3-rev136-1.25.0')
            {
                exclude group: 'org.apache.httpcomponents'
            }
implementation ('com.google.api-client:google-api-client-android:1.26.0')
            {
                exclude group: 'org.apache.httpcomponents'
            }
implementation 'com.google.http-client:google-http-client-gson:1.26.0'

and here the version that I use

compileSdkVersion 30
buildToolsVersion "30.0.3"

The problem is in this code lines(I think), and occurs only if I use ".requestScopes(new Scope(DriveScopes.DRIVE_FILE))":

GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
                .requestEmail()
                .build();
GoogleSignInClient client= GoogleSignIn.getClient(this,signInOptions);
Intent i= client.getSignInIntent();
startActivityForResult(i,400);

(it seems like the activity never returns any value). Without ".requestScopes(new Scope(DriveScopes.DRIVE_FILE))" the auth request is successful. Here my Google console configuration: The client ID (sorry, maybe it will appear as a link but stackOverflow tell me that I can't put img) and ".../auth/drive.file" is the authorization that I request in google Consent window that appears to the user. I don't know if it is important to say but I use a real phone and not the Android Studio emulator to test my app.


回答1:


I just solved it. For all those who encounter this problem: from the Google API console, remove the consent screen from the test state and publish it.




回答2:


Take a look at https://issuetracker.google.com/issues/178183308 where the issue was reported to Google.



来源:https://stackoverflow.com/questions/65853630/android-app-with-google-drive-api-stucks-after-choosing-an-account-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!