onConnectionFailed giving SIGN_IN_REQUIRED(4)(onConnectionFailed 给 SIGN_IN_REQUIRED(4))
问题描述
我正在开发一个想要使用 Google API 的 Android 应用程序.为此,我导入了 google-play-service-lib 项目.
我正在关注这个 链接 来初始化 GoogleApiClient 对象.p>
我的代码:
1) 在 onCreate() 方法中,我正在构建 GoogleApiClient 对象:
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(这个).addOnConnectionFailedListener(这个).addApi(Plus.API, null).addScope(Plus.SCOPE_PLUS_LOGIN).建造();2) 在onStart()中,我调用mGoogleApiClient.connect().
3) 我的活动实现ConnectionCallbacks 和 OnConnectionFailedListener.
4) 我的 onConnectionFailed() 方法如下所示:
public void onConnectionFailed(ConnectionResult 结果) {//在 dubug 结果中看起来像:ConnectionResult{//statusCode=SIGN_IN_REQUIRED,分辨率=PendingIntent//{41f8ca70: android.os.BinderProxy@41f8ca10}}尝试 {if(!mIntentInProgress && result.hasResolution()){mIntentInProgress=true;result.startResolutionForResult(mActivity, RC_SIGN_IN);}} 捕捉(SendIntentException e){e.printStackTrace();}}5) 我的 onActivityResult() 方法包含:
if (requestCode == RC_SIGN_IN) {if (!mGoogleApiClient.isConnecting()) {mGoogleApiClient.connect();}}当我运行我的应用程序时,我得到一个 Toast 表示弹出了一个内部错误.我确实在 Google 控制台中创建了该项目.
我也遇到了同样的问题.
来自文档:客户端可以选择不使用 API 继续,也可以调用 startResolutionForResult(Activity, int) 提示用户登录.
所以你应该尝试使用 startResolutionForResult() 函数登录
@Override公共无效onConnectionFailed(连接结果结果){if (result.hasResolution()) {尝试 {//!!!result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);} 捕捉(SendIntentException e){mPlusClient.connect();}}mConnectionResult = 结果;}I am developing an Android application where I want to use the Google API. For that I have imported the google-play-service-lib project.
I am following this link to initialize GoogleApiClient object.
My code:
1) In the onCreate() method I am building the GoogleApiClient object:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
2) In onStart(), I call mGoogleApiClient.connect().
3) My activity implements ConnectionCallbacks and OnConnectionFailedListener.
4) My onConnectionFailed() method looks like:
public void onConnectionFailed(ConnectionResult result) {
//in dubug result looks like : ConnectionResult{
//statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent
// {41f8ca70: android.os.BinderProxy@41f8ca10}}
try {
if(!mIntentInProgress && result.hasResolution())
{
mIntentInProgress=true;
result.startResolutionForResult(mActivity, RC_SIGN_IN);
}
} catch (SendIntentException e) {
e.printStackTrace();
}
}
5) My onActivityResult() method contains:
if (requestCode == RC_SIGN_IN) {
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
When I run my app I get a Toast that says that an internal error popped up. I did create the project in the Google console.
I had the same problem.
From documentation: The client may choose to continue without using the API or it may call startResolutionForResult(Activity, int) to prompt the user to sign in.
So you should try to sign in by using startResolutionForResult() function
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
// !!!
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
mConnectionResult = result;
}
这篇关于onConnectionFailed 给 SIGN_IN_REQUIRED(4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:onConnectionFailed 给 SIGN_IN_REQUIRED(4)
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
