选择帐户后,带有Google Drive API的Android应用卡住了.为什么? [英] Android App with Google Drive API stucks after choosing an account. Why?

查看:93
本文介绍了选择帐户后,带有Google Drive API的Android应用卡住了.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何将Google Drive API集成到我的Android应用中(使用Android Studio).我已经尝试过在这里找到的示例应用程序( https://github.com/googleworkspace/android-samples/tree/master/drive/deprecation ),但是在配置Google API控制台后,当我选择一个帐户时,我的应用陷入了无限循环.为什么?问题出在哪儿?我也尝试过使用此( https://youtu.be/5bSEIQYJzKs )教程,但是我遇到了同样的问题.这是我的build.gradle特定行:

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'

,这里是我使用的版本

compileSdkVersion 30
buildToolsVersion "30.0.3"

问题出在此代码行中(我认为),并且仅当我使用".requestScopes(new Scope(DriveScopes.DRIVE_FILE))"时出现:

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);

(似乎该活动从不返回任何值).没有".requestScopes(new Scope(DriveScopes.DRIVE_FILE))"身份验证请求成功.这是我的Google控制台配置:客户端ID (对不起,也许它将显示为链接,但是stackOverflow告诉我我不能放置img)和".../auth/drive.file"是我在Google同意窗口中向用户显示的请求授权.我不知道该说什么是否重要,但我使用的是真实手机,而不是Android Studio模拟器来测试我的应用.

(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.

推荐答案

我刚刚解决了它.对于所有遇到此问题的用户:在Google API控制台中,从测试状态中删除同意屏幕,然后发布该同意屏幕.

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.

这篇关于选择帐户后,带有Google Drive API的Android应用卡住了.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆