2017-12-22 24 views
0

Google 드라이브에있는 기존 파일에서 데이터를 가져 오려고합니다. 검색은 정확하게 일부 메타 데이터를 반환하지만, 파일의 마지막 수정 날짜를 얻으려고하면 null이됩니다.google.api.client는 파일에서 null을 가져옵니다.

FileList result = null; 
     try { 
      result = mService.files().list() 
        .setQ("name = file.db and trashed = false") 
        .execute(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
Log.d("Sync_drive", result); 
List<com.google.api.services.drive.model.File> files; 
    if (result != null) { 
    for (com.google.api.services.drive.model.File fileD : files) { 
dateModified = String.valueOf(fileD.getModifiedTime().getValue()); 
gdid = fileD.getId(); 
Log.d("Sync_drive", "id: " + gdid); 
} 

결과 :

Sync_drive: {"files":[{"id":"1jX2w7F0Pjx28ug0lvjEIp4Kje6fw5JyF","kind":"drive#file","mimeType":"application/octet-stream","name":"file.db"}],"incompleteSearch":false,"kind":"drive#fileList"} 

프로세스 : PID : 27987 java.lang.NullPointerException이 님의 시도 나는이 내 코드의 일부이다
을 이해하지 못하는 null 객체 참조에서 가상 메서드 'long com.google.api.client.util.DateTime.getValue()'를 호출하십시오.

답변

0

먼저 구글에서 클라이언트에 연결해야합니다 : 여기 하는 예입니다

protected synchronized void buildGoogleApiClient() { 
     if (checkPlayServices()) { 
        .requestServerAuthCode(BuildConfig.GOOGLE_WEB_CLIENT_ID) 
        .requestEmail() 
        .build(); 
      // Build a GoogleApiClient with access to the Google Sign-In API and the 
      // options specified by gso. 
      mGoogleApiClient = new GoogleApiClient.Builder(this) 
        .addConnectionCallbacks(this) 
        .addOnConnectionFailedListener(this) 
        .addApi(/*Api for google Drive*/) 
        .enableAutoManage(this, this) 
        .build(); 
      mGoogleApiClient.connect(); 

     } 
    } 

당신 같은 활동에 콜백 함수를 구현해야 : , GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks

일단 클라이언트가 연결되면 파일에서 데이터를 가져올 수 있습니다.

+0

연결되지 않은 경우 결과가 표시되지 않습니다. 맞습니까? 다음 코드를 사용합니다. [https://developers.google.com/drive/v3/web/quickstart/android] – user2847219

+0

예. 먼저 연결해야합니다. –

+0

샘플 코드 살펴보기 https://github.com/googledrive/android-quickstart –