找不到驱动器Id。你有权查看此文件?谷歌Android驱动的集成 [英] Cannot find DriveId. Are you authorized to view this file? Android google drive integration

查看:240
本文介绍了找不到驱动器Id。你有权查看此文件?谷歌Android驱动的集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用从<一下面code href=\"https://github.com/googledrive/android-demos/blob/master/src/com/google/android/gms/drive/sample/demo/EditContentsActivity.java\"相对=nofollow> github上,
但它显示了以下错误:

 敬酒说找不到驱动器Id。你有权查看此文件?

我不知道这背后的原因。

我已阅读配发关于谷歌驱动器的集成,我想保存字符串转换成谷歌的车程,也找回,我已经使用这个演示,但它给我的错误。请任何人给我演示了我的要求。

  / **
 *版权所有2013谷歌公司保留所有权利。
 *
 *在Apache许可,2.0版(以下简称许可证);你可能不使用这个文件除了
 *遵守许可证。您可以在获得许可证的副本
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意,根据分布式软件
 *许可分布在原样的基础,没有担保或任何形式的条件,无论是
 *前preSS或暗示的保证。查看许可证的特定语言的管理权限和
 *根据许可证的限制。
 * /包com.google.android.gms.drive.sample.demo;进口java.io.IOException异常;
进口java.io.OutputStream中;进口android.content.Context;
进口android.os.Bundle;
进口android.util.Log;进口com.google.android.gms.common.api.ResultCallback;
进口com.google.android.gms.drive.Drive;
进口com.google.android.gms.drive.DriveApi.ContentsResult;
进口com.google.android.gms.drive.DriveApi.DriveIdResult;
进口com.google.android.gms.drive.DriveFile;/ **
 *一个活动来说明如何编辑驱动文件的内容。
 * /
公共类EditContentsActivity扩展BaseDemoActivity {    私有静态最后弦乐TAG =EditContentsActivity;    @覆盖
    公共无效onConnected(捆绑connectionHint){
        super.onConnected(connectionHint);        最后ResultCallback&LT; D​​riveIdResult&GT; idCallback =新ResultCallback&LT; D​​riveIdResult&GT;(){
            @覆盖
            公共无效onResult(DriveIdResult结果){
                如果(!result.getStatus()。isSuccess()){
                    showMessage(无法找到驱动器Id你无权查看此文件?);
                    返回;
                }
                DriveFile文件= Drive.DriveApi.getFile(getGoogleApiClient(),result.getDriveId());
                新EditContentsAsyncTask(EditContentsActivity.this).execute(文件);
            }
        };
        Drive.DriveApi.fetchDriveId(getGoogleApiClient(),EXISTING_FILE_ID)
              .setResultCallback(idCallback);
    }    公共类EditContentsAsyncTask扩展ApiClientAsyncTask&LT; D​​riveFile,太虚,布尔&GT; {        公共EditContentsAsyncTask(上下文的背景下){
            超级(上下文);
        }        @覆盖
        保护布尔doInBackgroundConnected(DriveFile参数... args){
            DriveFile文件= ARGS [0];
            尝试{
                ContentsResult contentsResult = file.openContents(
                        getGoogleApiClient(),DriveFile.MODE_WRITE_ONLY,NULL).await();
                如果(!contentsResult.getStatus()。isSuccess()){
                    返回false;
                }
                为OutputStream的OutputStream = contentsResult.getContents()的getOutputStream()。
                outputStream.write(Hello World的.getBytes());
                com.google.android.gms.common.api.Status状态= file.commitAndCloseContents(
                        。getGoogleApiClient(),contentsResult.getContents())等待();
                返回status.getStatus()isSuccess()。
            }赶上(IOException异常五){
                Log.e(TAG,IOException异常而追加到输出流,E);
            }
            返回false;
        }        @覆盖
        保护无效onPostExecute(布尔结果){
            如果(!结果){
                showMessage(错误在编辑内容);
                返回;
            }
            showMessage(成功编辑的内容);
        }
    }
}


解决方案

作为消息状态,你的应用程序需要被授权查看特定文件,以便从您的应用程序具有的 Drive.File范围访问。

您可以得到授权通过让用户在打开文件对话框中选择,或通过具有创建的文件的访问特定文件。

I am using the below code from github, but it shows the following error:

toast that Cannot find DriveId. Are you authorized to view this file?

I don't know what is the reason behind this.

I have read allot about Google drive integration and I want to save STRING into Google drive and also to retrieve, I have used this demo but it is giving me errors. please anyone provide me demo for my requirement

/**
 * Copyright 2013 Google Inc. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gms.drive.sample.demo;

import java.io.IOException;
import java.io.OutputStream;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.drive.Drive;
import com.google.android.gms.drive.DriveApi.ContentsResult;
import com.google.android.gms.drive.DriveApi.DriveIdResult;
import com.google.android.gms.drive.DriveFile;

/**
 * An activity to illustrate how to edit contents of a Drive file.
 */
public class EditContentsActivity extends BaseDemoActivity {

    private static final String TAG = "EditContentsActivity";

    @Override
    public void onConnected(Bundle connectionHint) {
        super.onConnected(connectionHint);

        final ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
            @Override
            public void onResult(DriveIdResult result) {
                if (!result.getStatus().isSuccess()) {
                    showMessage("Cannot find DriveId. Are you authorized to view this file?");
                    return;
                }
                DriveFile file = Drive.DriveApi.getFile(getGoogleApiClient(), result.getDriveId());
                new EditContentsAsyncTask(EditContentsActivity.this).execute(file);
            }
        };
        Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FILE_ID)
              .setResultCallback(idCallback);
    }

    public class EditContentsAsyncTask extends ApiClientAsyncTask<DriveFile, Void, Boolean> {

        public EditContentsAsyncTask(Context context) {
            super(context);
        }

        @Override
        protected Boolean doInBackgroundConnected(DriveFile... args) {
            DriveFile file = args[0];
            try {
                ContentsResult contentsResult = file.openContents(
                        getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null).await();
                if (!contentsResult.getStatus().isSuccess()) {
                    return false;
                }
                OutputStream outputStream = contentsResult.getContents().getOutputStream();
                outputStream.write("Hello world".getBytes());
                com.google.android.gms.common.api.Status status = file.commitAndCloseContents(
                        getGoogleApiClient(), contentsResult.getContents()).await();
                return status.getStatus().isSuccess();
            } catch (IOException e) {
                Log.e(TAG, "IOException while appending to the output stream", e);
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (!result) {
                showMessage("Error while editing contents");
                return;
            }
            showMessage("Successfully edited contents");
        }
    }
}

解决方案

As the message states, your app need to be authorized to view the particular file in order to edit it since your app has Drive.File scope access.

You can get authorized to access the particular file by having the user select in the open file dialog, or by virtue of having created the file.

这篇关于找不到驱动器Id。你有权查看此文件?谷歌Android驱动的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆