Google 驱动器:登录失败。登录指定帐户时出错
Google Drive: sign in failed. Error signing into the specified account
我正在尝试让我的用户 select 将文件上传到我的服务器以进行更多处理。我无法让登录正常工作,也无法弄清楚原因。下面是我用来启动握手的代码 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 地图中使用了相同的凭据。在我的清单中,我有以下内容:
<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 Drive 不需要我传递 api 密钥?那是对的吗?除此之外我想不出任何东西——但是文档没有说它是必需的。
我的 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'
我认为您没有在 build.gradle 文件中添加 com.android.application
。您所指的文档授权请求但不进行身份验证。
要了解更多关于访问 Google 驱动器的身份验证,请参阅 Android Quick-start to access Drive REST API 上的官方文档。
这包括:
- 获取 SHA1 指纹。
- 启用驱动器API
- 创建一个新的 Android 项目
- 配置项目
- 添加项目源文件
- 运行 应用
希望对您有所帮助!!
我运行进入同样的东西。看起来您还需要设置 OAuth 2.0 凭证。一旦我这样做了,它就奏效了。
我正在尝试让我的用户 select 将文件上传到我的服务器以进行更多处理。我无法让登录正常工作,也无法弄清楚原因。下面是我用来启动握手的代码 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 地图中使用了相同的凭据。在我的清单中,我有以下内容:
<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 Drive 不需要我传递 api 密钥?那是对的吗?除此之外我想不出任何东西——但是文档没有说它是必需的。
我的 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'
我认为您没有在 build.gradle 文件中添加 com.android.application
。您所指的文档授权请求但不进行身份验证。
要了解更多关于访问 Google 驱动器的身份验证,请参阅 Android Quick-start to access Drive REST API 上的官方文档。
这包括:
- 获取 SHA1 指纹。
- 启用驱动器API
- 创建一个新的 Android 项目
- 配置项目
- 添加项目源文件
- 运行 应用
希望对您有所帮助!!
我运行进入同样的东西。看起来您还需要设置 OAuth 2.0 凭证。一旦我这样做了,它就奏效了。