android drive api这个文件不可打开

时间:2017-01-22 11:18:44

标签: android google-drive-android-api

Google Drive API新手,似乎无法阅读Google Doc文件的内容。我能够读取元数据,但文件不会打开"。我得到此错误代码10,状态{statusCode =此文件无法打开。,resolution = null}。如何访问Google文档的内容?



private void open() {
        Log.w(TAG, mSelectedFileDriveId.getResourceId());
        DriveFile driveFile = mSelectedFileDriveId.asDriveFile();

        driveFile.getMetadata(mGoogleApiClient).setResultCallback(new ResultCallbacks<DriveResource.MetadataResult>() {
            @Override
            public void onSuccess(@NonNull DriveResource.MetadataResult metadataResult) {
                Log.w(TAG, "Title: "+ metadataResult.getMetadata().getTitle());
                Log.w(TAG, "Filename: "+ metadataResult.getMetadata().getOriginalFilename());
                Log.w(TAG, "MimeType: "+ metadataResult.getMetadata().getMimeType());
                Log.w(TAG, "DriveId: "+ metadataResult.getMetadata().getDriveId());
                Log.w(TAG, "Description: "+ metadataResult.getMetadata().getDescription());
            }

            @Override
            public void onFailure(@NonNull Status status) {
                Log.w(TAG, "Failed to get metadata");
            }
        });

        driveFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).setResultCallback(driveContentsResultResultCallbacks);
        mSelectedFileDriveId = null;
    }
&#13;
&#13;
&#13;

&#13;
&#13;
private final ResultCallbacks<DriveApi.DriveContentsResult> driveContentsResultResultCallbacks = new ResultCallbacks<DriveApi.DriveContentsResult>() {
        @Override
        public void onSuccess(@NonNull DriveApi.DriveContentsResult driveContentsResult) {
            Log.i(TAG, "File contents opened");

            // Read from the input stream an print to LOGCAT
            DriveContents driveContents = driveContentsResult.getDriveContents();
            BufferedReader reader = new BufferedReader(new InputStreamReader(driveContents.getInputStream()));
            StringBuilder builder = new StringBuilder();
            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            String contentsAsString = builder.toString();
            Log.i(TAG, contentsAsString);

            // Close file contents
            driveContents.discard(mGoogleApiClient);
        }

        @Override
        public void onFailure(@NonNull Status status) {
            Log.w(TAG, "Error while opening the file contents");
            Log.w(TAG, "Status: "+status.getStatus());
            Log.w(TAG, "Status Code: "+status.getStatusCode());
            Log.w(TAG, "Status Message: "+status.getStatusMessage());
        }
    };
&#13;
&#13;
&#13;

&#13;
&#13;
1ysPUyGHKwAz_wj7K17IKg3Vn0DFtURdD5_Mxn2xsBAo
Title:TEST
Filename: null
MimeType: application/vnd.google-apps.document
DriveId:DriveId:CAESLDF5c1BVeUdIS3dBel93ajdLMTdJS2czVm4wREZ0VVJkRDVfTXhuMnhzQkFvGKJFIOby8oOMVigA
Description: null
Error while opening the file contents
Status: Status{statusCode=This file is not openable., resolution=null}
Status Code: 10
Status Message: This file is not openable.
&#13;
&#13;
&#13;

0 个答案:

没有答案