gpt4 book ai didi

android - GoogleApiClient 连接总是第一次失败但第二次成功

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:09 25 4
gpt4 key购买 nike

我通过 GoogleApiClient 为应用设置了 google plus 登录。

每当应用程序首次安装并尝试通过 GoogleApiClient 建立连接时,它永远不会成功,并且总是以 onConnectionFailedresult 结束包含:

ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{4130e760: android.os.BinderProxy@4130e700}}

但是当第二次登录时,它的调用成功并且 onConnected 命中。为什么一次就能成功?

我的 Builder 参数有问题吗?

public void connectGoogleApi() {
mGoogleApiClient = new GoogleApiClient.Builder(mainAppContext).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();
mGoogleApiClient.connect();
}

public void onConnectionFailed(ConnectionResult result) {
if (!result.hasResolution()) {
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
return;
}

if (!mIntentInProgress) {
// Store the ConnectionResult for later usage
mConnectionResult = result;
resolveSignInError();
}

}

最佳答案

正如官方文档所述here :

If you are using GoogleApiClient to connect to APIs that require authentication, like Google Drive or Google Play Games, there's a good chance your first connection attempt will fail and your app will receive a call to onConnectionFailed() with the SIGN_IN_REQUIRED error because the user account was not specified.

关于android - GoogleApiClient 连接总是第一次失败但第二次成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27951308/

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