【发布时间】:2017-02-13 10:12:43
【问题描述】:
我正在尝试将适用于 Android 的 Google Drive API 与我的 Android 应用程序集成。
我的前辈使用应用包名称和我机器上的SHA1 在Google Developer 控制台上创建了一个项目,并生成了OAuth 2.0 客户端ID(我无权访问该帐户)。
点击按钮后,我必须允许用户访问 Drive 上的文件,以便将它们上传到服务器。
我调用以下代码onClick():
mGoogleApiClient = new GoogleApiClient.Builder(Activity.this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(Activity.this)
.addOnConnectionFailedListener(Activity.this)
.build();
mGoogleApiClient.connect();
这会调用onConnectionFailed() 回调:
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "Connection failed");
if (connectionResult.hasResolution()) {
try {
Log.i(TAG, "Connection failed - Trying again");
connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
}
} else {
Log.i(TAG, "Connection failed, Code : " + connectionResult.getErrorCode());
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
}
}
连接失败并再次尝试。重试时,它会调用onActivityResult() 并再次尝试连接:
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if (requestCode == Constants.RESOLVE_CONNECTION_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Log.i(TAG, "Code match");
mGoogleApiClient.connect();
}
}
这一次连接尝试再次失败,错误代码为 8,并显示消息“应用程序在使用 Google Play 服务时遇到问题。如果问题仍然存在,请联系开发人员寻求帮助。”
我也读过这个: <Your App> is having trouble with Google Play services - When using GoogleApiClient, it always trigger onConnectionFailed,但没有帮助。
我尝试在 Google 上查找它,但没有任何帮助。任何帮助都会很棒!
【问题讨论】:
标签: android google-play-services