- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试将 Google 云端硬盘集成到我的应用程序中,但收效甚微。使用 Quick Start 存储库中的代码,每次选择用户帐户登录时,我都会收到以下错误消息:
I/DriveDemo: GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{867e070: android.os.BinderProxy@13cdfe9}, message=null}
我已按照以下网址中的说明进行操作:
并关注视频:
我还查看了许多 Stack Overflow 问题和答案,却不知道自己做错了什么。
list .xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lightkeeper54.chuck.drivedemo">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
代码:
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
// Create the API client and bind it to an instance variable.
// We use this instance as the callback for connection and connection
// failures.
// Since no account name is passed, the user is prompted to choose.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
// Connect the client. Once connected, the camera is launched.
mGoogleApiClient.connect();
}
@Override
protected void onPause() {
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}
super.onPause();
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
switch (requestCode) {
case REQUEST_CODE_CAPTURE_IMAGE:
// Called after a photo has been taken.
if (resultCode == Activity.RESULT_OK) {
// Store the image data as a bitmap for writing later.
mBitmapToSave = (Bitmap) data.getExtras().get("data");
}
break;
case REQUEST_CODE_CREATOR:
// Called after a file is saved to Drive.
if (resultCode == RESULT_OK) {
Log.i(TAG, "Image successfully saved.");
mBitmapToSave = null;
// Just start the camera again for another photo.
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
REQUEST_CODE_CAPTURE_IMAGE);
}
break;
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
// Called whenever the API client fails to connect.
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// show the localized error dialog.
GoogleApiAvailability.getInstance().getErrorDialog(this, result.getErrorCode(), 0).show();
return;
}
// The failure has a resolution. Resolve it.
// Called typically when the app is not yet authorized, and an
// authorization
// dialog is displayed to the user.
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "API client connected.");
if (mBitmapToSave == null) {
// This activity has no UI of its own. Just start the camera.
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
REQUEST_CODE_CAPTURE_IMAGE);
return;
}
saveFileToDrive();
}
@Override
public void onConnectionSuspended(int cause) {
Log.i(TAG, "GoogleApiClient connection suspended");
}
最佳答案
基于文档 - SIGN_IN_REQUIRED
The client attempted to connect to the service but the user is not signed in. The client may choose to continue without using the API. Alternately, if
hasResolution()
returns true the client may callstartResolutionForResult(Activity, int)
to prompt the user to sign in. After the sign in activity returns withRESULT_OK
further attempts should succeed.
您也可以查看@Cheok 的问题,SO post建议按照要求正确添加 SHA-1 和包名称,并在设置项目凭据后启用 API。
希望这些信息对您有所帮助。
关于android - GoogleApiClient 连接失败 : ConnectionResult{statusCode=SIGN_IN_REQUIRED,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42180244/
我在这里做 google + integartion。我正在使用以下代码,但我面临的错误是:onConnectionFailed: ConnectionResult.getErrorCode() =
[编辑] - 赏金 我正在尝试将我的 Android 应用程序与 Google Drive 连接以同步 MP3 音频文件。需要使用 GoogleDriveAndroidApi 和 GoogleApiC
我已经实现了检查播放服务是否照常可用的代码: mGooglePlayServicesAvailable = false; GoogleApiAvailability apiAvailability =
我尝试将 Google 云端硬盘集成到我的应用程序中,但收效甚微。使用 Quick Start 存储库中的代码,每次选择用户帐户登录时,我都会收到以下错误消息: I/DriveDemo: Google
当我尝试按照有关如何检查是否安装了 Google Play 服务的示例进行操作时,我收到以下错误:servicesConnected 方法内的行中出现“connectionResult cannot
我正在制作一个应用程序并将 Google Drive Android API 集成到其中。我有一个主要 Activity ,然后是一个 fragment ,该 fragment 打开导致谷歌驱动器。但
我正在开发将 Google Drive 集成到我的应用程序中的应用程序。以下是我的代码,我只是从示例代码中复制而来,但在连接 Google Drive 时出现异常。 异常:onConnectionFa
我想制作一个简单的可穿戴应用程序并通过数据层进行连接。手持模块(使用:S5)一切正常,但可穿戴设备(使用:Moto 360)总是抛出错误: onConnectionFailed: Connection
为什么 GoogleApiClient 的 blockingConnect 方法返回 ConnectionResult.CANCELED 而在同一调用期间我从 OnConnectionFailedLi
已实现 this sample在手机和平板电脑上一切都很完美!但是在 Android TV ADT-1 v5.0.2 build LRX22G 中,这些 Eloquent 消息出现了。 GmsCl
google play 服务适用于 Lollipop ,但当涉及到 kitkat 和更低版本时,即使设备上安装了 google-play-services,它也会给出 ConnectionResult
我想使用 Google Plus 帐户登录我的应用程序。我编写了此代码,但显示强制关闭错误。 主要 Activity 代码: public class MainActivity extends App
我曾尝试使用 google fit 开发应用程序。我关注 This关联 当我尝试运行该应用程序时,出现以下错误 10-27 11:55:19.966:I/Google Fit(6016):连接失败。原
我是一名优秀的程序员,十分优秀!