Android 错误:ConnectionResult{statusCode=INTERNAL_ERROR,resolution=null}
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21280794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error : ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null}
提问by N Sharma
I am developing the application where I am integrating the Google Drive in my App. Below is my code which is I simply copied from the sample code but I am getting exception when connecting with Google Drive.
我正在开发将 Google Drive 集成到我的应用程序中的应用程序。下面是我的代码,我只是从示例代码中复制了它,但是在与 Google Drive 连接时出现异常。
Exception : ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null}
in the onConnectionFailed() method.
例外:ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null}
在 onConnectionFailed() 方法中。
Please guys share your views.
请各位大侠分享一下看法。
public class MainActivity extends Activity implements ConnectionCallbacks,
OnConnectionFailedListener {
private static final String TAG = "android-drive-quickstart";
private static final int REQUEST_CODE_CAPTURE_IMAGE = 1;
private static final int REQUEST_CODE_CREATOR = 2;
private static final int REQUEST_CODE_RESOLUTION = 3;
private GoogleApiClient mGoogleApiClient;
private Bitmap mBitmapToSave;
/**
* Create a new file and save it to Drive.
*/
private void saveFileToDrive() {
// Start by creating a new contents, and setting a callback.
Log.i(TAG, "Creating new contents.");
final Bitmap image = mBitmapToSave;
Drive.DriveApi.newContents(mGoogleApiClient).addResultCallback(new OnNewContentsCallback() {
@Override
public void onNewContents(ContentsResult result) {
// If the operation was not successful, we cannot do anything
// and must
// fail.
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Failed to create new contents.");
return;
}
// Otherwise, we can write our data to the new contents.
Log.i(TAG, "New contents created.");
// Get an output stream for the contents.
OutputStream outputStream = result.getContents().getOutputStream();
// Write the bitmap data from it.
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
// Create the initial metadata - MIME type and title.
// Note that the user will be able to change the title later.
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("image/jpeg").setTitle("Android Photo.png").build();
// Create an intent for the file chooser, and start it.
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialContents(result.getContents())
.build(mGoogleApiClient);
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.i(TAG, "Failed to launch file chooser.");
}
}
});
}
@Override
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.
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 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 (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 onDisconnected() {
Log.i(TAG, "API client disconnected.");
}
}
采纳答案by N Sharma
I solved the issue from register the application and generate signing certificate fingerprint.
我从注册应用程序并生成签名证书指纹解决了这个问题。
I followed above links and It solved my problem.
我按照上面的链接,它解决了我的问题。
回答by Daniel F
Heads up!There's a problem in the Developers Console.
当心!开发者控制台中存在问题。
If you are getting this bug even after 1) making sure that you have registered the package namewith its corresponding certificate fingerprint, and 2) are (re)using an already existingproject, thenyou should check that this project has an product nameand an email address(double check that one specially) associated with it, both to be found in the "consent screen" section.
如果您在 1) 确保已使用相应的证书指纹注册包名称,并且 2) 正在(重新)使用已经存在的项目后仍然遇到此错误,那么您应该检查该项目是否具有产品名称和一个与其关联的电子邮件地址(仔细检查那个),都可以在“同意屏幕”部分找到。
Very old projects may not have these two fields populated. Newer projects have these fields filled out with some default values.
非常旧的项目可能没有填充这两个字段。较新的项目在这些字段中填写了一些默认值。
Took me a day to find this...
找了一天才找到这个。。。
回答by yasir shehzad
I resolve this issue by signing my Google Drive application on API console following these steps
我通过按照以下步骤在 API 控制台上签署我的 Google Drive 应用程序来解决此问题
- Go to the Google Developers Console.
- Select a project, or create a new one.
- In the sidebar on the left, expand APIs & auth. Next, click APIs.
- In the list of APIs, make sure the status is ON for the Drive API.
- In the sidebar on the left, select Credentials.
- 转到 Google 开发者控制台。
- 选择一个项目,或创建一个新项目。
- 在左侧边栏中,展开 APIs & auth。接下来,单击 API。
- 在 API 列表中,确保 Drive API 的状态为 ON。
- 在左侧的边栏中,选择凭据。
If your application needs to submit authorized requests:
如果您的应用程序需要提交授权请求:
- Under OAuth, click Create new Client ID.
- Select Installed application and Android.
- In the Package name field, enter your Android app's package name.
- Paste the SHA1 fingerprint into the form where requested.
- Click Create Client ID.
- 在 OAuth 下,单击创建新客户端 ID。
- 选择已安装的应用程序和 Android。
- 在包名称字段中,输入您的 Android 应用程序的包名称。
- 将 SHA1 指纹粘贴到请求的表单中。
- 单击创建客户端 ID。
回答by jpprade
For me the problem was that when in the example there was :
对我来说,问题是在示例中有:
.addApi(Drive.API)
And I didn't added the drive api in the console
而且我没有在控制台中添加驱动器api
this error message helped me to figure out the issue
此错误消息帮助我找出问题
com.google.android.gms.drive.auth.c: Authorization failed: server returned error: Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.. See https://developers.google.com/drive/handle-errorsfor details.
com.google.android.gms.drive.auth.c:授权失败:服务器返回错误:未配置访问。未为您的项目启用 API,或者您的 API 密钥上配置了每个 IP 或每个引用者的限制,并且请求与这些限制不匹配。请使用 Google Developers Console 更新您的配置。有关详细信息,请参阅 https://developers.google.com/drive/handle-errors。
回答by alnassre
Don't forget the permissions:
不要忘记权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
回答by Cheryl Simon
Do you have any error messages in logcat? The most likely cause of a failed connection is that you haven't properly setup an app in the cloud console.
您在 logcat 中有任何错误消息吗?连接失败的最可能原因是您没有在云控制台中正确设置应用程序。
See the instructions here: https://developers.google.com/drive/android/auth
回答by Pablo Carbajal
In my case, I had to change the Client ID to use the exact package name of the activity class building the GoogleApiClient object, not a higher-level package.
就我而言,我必须更改客户端 ID 以使用构建 GoogleApiClient 对象的活动类的确切包名称,而不是更高级别的包。
回答by Robin Singh
I was also getting the same error. For my project, Drive API was not enabled under API & auth -> APIs. After enabling this Drive API, this problem was resolved.
我也遇到了同样的错误。对于我的项目,未在 API & auth -> APIs 下启用 Drive API。启用此 Drive API 后,此问题已解决。
回答by csamiro
I solved adding this line to gradle:
我解决了将这一行添加到 gradle 的问题:
compile 'com.google.android.gms:play-services-identity:8.1.0'
回答by Prashant Date
In Android Studio go to
在 Android Studio 中转到
Tool-> Android-SDK Manager -> Google Play Service
工具-> Android-SDK 管理器-> Google Play 服务
Update the Google Play Service..I am sure it will work
更新Google Play 服务..我相信它会起作用