DCo*_*der 21 android google-play google-play-services
我正在开发一个Android应用程序,我想使用Google API.为此,我导入了google-play-service-lib项目.
我正在关注此链接以初始化GoogleApiClient对象.
我的代码:
1)在onCreate()我构建GoogleApiClient对象的方法中:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
Run Code Online (Sandbox Code Playgroud)
2)在onStart(),我打电话mGoogleApiClient.connect().
3)我的活动实现了 ConnectionCallbacks和OnConnectionFailedListener.
4)我的onConnectionFailed()方法看起来像:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
5)我的onActivityResult()方法包含:
if (requestCode == RC_SIGN_IN) {
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时,我得到一个Toast,表示弹出了一个内部错误.我确实在Google控制台中创建了该项目.
小智 23
我有同样的问题.
从文档:客户端可以选择继续而不使用API,也可以调用startResolutionForResult(Activity,int)来提示用户登录.
因此,您应该尝试使用startResolutionForResult()函数登录
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
// !!!
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
mConnectionResult = result;
}
Run Code Online (Sandbox Code Playgroud)
检查您是否使用上传到Google Play开发人员控制台的apk中的密钥库对应用进行签名(如果进行测试,您可以上传为alpha并发布,同时保持私有).
如果不是这样,那可能是其他的事情.确保您的帐户的电子邮件地址列在帐户详细信息页面中的测试人员中(在设置菜单上带有齿轮图标),并且许可的响应设置为许可,而不是RESPOND_NORMALLY
此错误表明用户需要授权您的应用程序。有一个完整的工作流程,按照https://developers.google.com/+/mobile/android/getting-started上的教程查找“onConnectionFailed”
| 归档时间: |
|
| 查看次数: |
27257 次 |
| 最近记录: |