我试图让我的用户选择要上传到我的服务器以进行更多处理的文件。我无法让登录正常工作,也无法弄清楚原因。下面是我用来启动与 Google 的握手的代码:
public GoogleApiClient getGoogleApiClient() {
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
return mGoogleApiClient;
}
private void getDataFromGoogleDrive() {
try {
IntentSender intentSender = Drive.DriveApi.newOpenFileActivityBuilder().build(getGoogleApiClient());
getActivity().startIntentSenderForResult(intentSender, RC_SIGN_IN, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.w(TAG, "Unable to send intent", e);
getGoogleApiClient().connect();
}
}
public void onConnected(Bundle bundle) {
if (getGoogleApiClient().isConnected()) {
getDataFromGoogleDrive();
}
}
public void onConnectionSuspended(int i) {
}
public void onConnectionFailed(ConnectionResult connectionResult) {
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(getActivity(), RC_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
}
} else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), getActivity(), 0).show();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == RC_SIGN_IN) {
if (!getGoogleApiClient().isConnecting()) {
getGoogleApiClient().connect();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
我也遵循了这里的指示:
我在这里遗漏了什么吗?我的凭据是准确的,因为我也在 Google map 上使用了相同的凭据。在我的 list 中,我有以下内容:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/google_api_key" />
我注意到 Google 云端硬盘不需要我传递 API key ?那是对的吗?除此之外,我想不出任何东西——但文档并没有说它是必需的。
我的 build.grade
文件依赖在这里:
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:support-annotations:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'
最佳答案
我遇到了同样的事情。看起来您还需要设置 OAuth 2.0 凭证。一旦我这样做了,它就奏效了。
关于android - Google Drive : sign in failed. 登录指定帐户时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32242218/