Google SignIn无法使用 [英] Google SignIn not working

查看:581
本文介绍了Google SignIn无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为客户提供Android应用,希望用户能够通过Google登录。
到目前为止,我已经实现了Google SignInButton,GoogleSignInOptions和GoogleApiClient。



然而,当我尝试登录时:

  googleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_REQUIRED); 

应用程序强制一旦以下列异常打开就会退出:

  E / AndroidRuntime:致命例外:main 
过程:de.nwt.slottynative,PID:24509
java.lang.RuntimeException:无法启动活动ComponentInfo {de.nwt.slottynative / de.nwt.slottynative.FullscreenActivity}:java.lang.IllegalStateException:无法使用登录模式:SIGN_IN_MODE_REQUIRED。模式已经设置为SIGN_IN_MODE_NONE
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2739)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2804)
at android .app.ActivityThread.access $ 900(ActivityThread.java:181)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler。 java:102)
在android.os.Looper.loop(Looper.java:145)
在android.app.ActivityThread.main(ActivityThrea d.java:6066)
在java.lang.reflect.Method.invoke(本地方法)
在java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
导致: java.lang.IllegalStateException:不能使用登录模式:SIGN_IN_MODE_REQUIRED。模式已设置为SIGN_IN_MODE_NONE
,com.google.android.gms.internal.zzmg.zzbC(未知源)
,com.google.android.gms.internal.zzmg.connect(未知源)
at de.nwt.slottynative.FullscreenActivity.onCreate(FullscreenActivity.java:239)
at android.app.Activity.performCreate(Activity.java:6368)
at android.app.Instrumentation .callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2692)
at android.app.Activ $ android.app.ActivityThread.access
(ActivityThread.java:181) )
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:145)
在android.app.ActivityThread。 main(ActivityThread.java:6066)
在java.lang.reflect.Method.invoke(本地方法)$ b $在java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

如果我尝试使用以下方式登录:

googleApiClient.connect );

我重定向到帐户选择片段,但登录失败:

  03-17 15:30:53.005 27135-27135 / de.nwt.slottynative D / handleSignInResult:handleSignInResult:false 
03-17 15:30:53.015 27135-27135 / de.nwt。 slottynative D / handleSignInResult:状态:Status {statusCode =未知状态码:12501,resolution = null}

以下是初始化API的代码:

  //< editor-fold desc =Google SDK Init> 
googleSignInOps = new GoogleSignInOptions.Builder()。requestEmail()。requestId()。requestProfile()
.requestIdToken(1042722069660-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com)。build();
googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this,new GoogleApiClient.OnConnectionFailedListener(){
@Override
onConnectionFailed(ConnectionResult connectionResult){
onGoogleConnectionFailed(connectionResult );
}
})。addApi(Auth.GOOGLE_SIGN_IN_API,googleSignInOps).build();
googleApiClient.connect();
googleLoginButton =(SignInButton)findViewById(R.id.googleLogin);
googleLoginButton.setSize(SignInButton.SIZE_WIDE);
$ b $ googleLoginButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
if(v.getId()== googleLoginButton.getId())
signIn();
}
});
//< / editor-fold>

预先感谢您的帮助!

解决方案

如果您使用的是SignIn API,您应该使用模式连接 - GoogleApiClient.SIGN_IN_MODE_OPTIONAL:

  googleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL)

请注意,如果您请求的权限和范围通过SignInOptions不会被用户授予,客户端仍将连接成功。


I have an Android app for a customer, who wishes the users be able to log in via Google. So far, I have implemented the Google SignInButton, the GoogleSignInOptions, and the GoogleApiClient.

However, when I try to log in with:

googleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_REQUIRED);

the application force quits as soon as it is opened with following exception:

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                 Process: de.nwt.slottynative, PID: 24509
                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{de.nwt.slottynative/de.nwt.slottynative.FullscreenActivity}: java.lang.IllegalStateException: Cannot use sign-in mode: SIGN_IN_MODE_REQUIRED. Mode was already set to SIGN_IN_MODE_NONE
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2739)
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2804)
                                                                     at android.app.ActivityThread.access$900(ActivityThread.java:181)
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                     at android.os.Looper.loop(Looper.java:145)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:6066)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at java.lang.reflect.Method.invoke(Method.java:372)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                                  Caused by: java.lang.IllegalStateException: Cannot use sign-in mode: SIGN_IN_MODE_REQUIRED. Mode was already set to SIGN_IN_MODE_NONE
                                                                     at com.google.android.gms.internal.zzmg.zzbC(Unknown Source)
                                                                     at com.google.android.gms.internal.zzmg.connect(Unknown Source)
                                                                     at de.nwt.slottynative.FullscreenActivity.onCreate(FullscreenActivity.java:239)
                                                                     at android.app.Activity.performCreate(Activity.java:6368)
                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2692)
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2804) 
                                                                     at android.app.ActivityThread.access$900(ActivityThread.java:181) 
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473) 
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                     at android.os.Looper.loop(Looper.java:145) 
                                                                     at android.app.ActivityThread.main(ActivityThread.java:6066) 
                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                     at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

If I try to log in with:

googleApiClient.connect();

I am redirected to the account selection fragment, however, the login fails:

03-17 15:30:53.005 27135-27135/de.nwt.slottynative D/handleSignInResult: handleSignInResult: false
03-17 15:30:53.015 27135-27135/de.nwt.slottynative D/handleSignInResult: status: Status{statusCode=unknown status code: 12501, resolution=null}

Here is the code which initializes the API:

//<editor-fold desc="Google SDK Init" >
    googleSignInOps = new GoogleSignInOptions.Builder().requestEmail().requestId().requestProfile()
            .requestIdToken("1042722069660-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com").build();
    googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
        @Override
        public void onConnectionFailed(ConnectionResult connectionResult) {
            onGoogleConnectionFailed(connectionResult);
        }
    }).addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOps).build();
    googleApiClient.connect();
    googleLoginButton = (SignInButton)findViewById(R.id.googleLogin);
    googleLoginButton.setSize(SignInButton.SIZE_WIDE);

    googleLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.getId() == googleLoginButton.getId())
                signIn();
        }
    });
    //</editor-fold>

Thanks in advance for your help!

解决方案

If you're using the SignIn API you should connect with the mode - GoogleApiClient.SIGN_IN_MODE_OPTIONAL:

googleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL)

Note that if permissions and scopes you have requested through the SignInOptions are not granted by the user the client will still connect successfuly.

这篇关于Google SignIn无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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