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)
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01