2014-03-12 1 views
3

나는 github, 에서 아래의 코드를 사용하고 있지만, 다음과 같은 오류를 보여줍니다 :이 뒤에 이유가 뭔지 모르는DriveId를 찾을 수 없습니다. 이 파일을 볼 권한이 있습니까? 안드로이드 구글 드라이브 통합

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

.

Google 드라이브 통합에 대한 정보를 읽었으며 STRING을 (를) Google 드라이브에 저장하고 검색하고 싶습니다.이 데모를 사용했지만 오류가 발생했습니다. 누구든지 앱이 앱이 Drive.File scope 액세스 할 수 있기 때문에 편집하기 위해 특정 파일을 볼 수있는 권한이해야, 내 요구 사항 메시지 상태로

/** 
* 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"); 
     } 
    } 
} 
+2

해결 방법이 있습니까? – OMAK

답변

2

에 대한 데모 나에게 제공하십시오.

사용자가 열린 파일 대화 상자에서 선택하도록하거나 파일을 작성함으로써 특정 파일에 대한 액세스 권한을 얻을 수 있습니다.

+0

앱에 대한 드라이브 전체 읽기 전용 범위 설정을 도와주세요 – OMAK

+0

현재 Android 관련 API를 통해 사용할 수 없습니다. REST API를 사용하여이 작업을 수행 할 수 있습니다. –

0

Google discussion here과 관련 있다고 생각합니다. 그렇다면 여기에 관객이 훨씬 넓기 때문에 거기서 닫을 것을 권합니다. READ/WRITE 문자열 문제를 처리하려면 여기 github code을 참조하십시오. 다른 문제는 승인과 관련이 있습니다. WIN7/Eclipse를 사용하고 있다면 this may help. 같은 정보는 here as well입니다. 일반적으로 많은 도움을 기대하지 마십시오. API는 상당히 새롭고 움직이는 목표입니다.

1

가 DriveId 의 ResourceId를 혼동 할 수 있습니다. EXISTING_FOLDER_ID 또는 EXISTING_FILE_ID에 대해 ResourceId를 사용해보십시오.

당신은 액세스 파일 또는 폴더에 대한 driveId를 사용하고있다

driveId.getResourceId().toString() 
0

문제 사용하여 얻을 수 있습니다. 그것은 틀렸다. 아래처럼 그 driveid의 ResourceID를 사용해야합니다 : 비 정적 정적에서

BaseDemoActivity.EXISTING_FOLDER_ID = driveId.getResourceId().toString(); 

변화 EXISTING_FOLDER_ID. 그 id를 추후 사용에 사용하십시오.