title: Fetch file contents based on Google drive ID
body: <p>In my  project I have to backup and restore .db SQLite database to google drive. I looked through google documentation and demo project. I have problem with DRIVE ID.</p>
  
  <p>that's my client:</p>
  
  <pre><code>mGoogleApiClient = new GoogleApiClient.Builder(this)
                  .addApi(Drive.API)
                  .addScope(Drive.SCOPE_FILE)
                  .addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .build();
  </code></pre>
  
  <p>I've created  file as google showed:</p>
  
  <pre><code>public class CreateFileActivity extends BaseDemoActivity {
  
  @Override
  public void onConnected(Bundle connectionHint) {
      super.onConnected(connectionHint);
      // create new contents resource
      Drive.DriveApi.newContents(getGoogleApiClient())
              .setResultCallback(contentsCallback);
  }
  
  final private ResultCallback&lt;ContentsResult&gt; contentsCallback = new
          ResultCallback&lt;ContentsResult&gt;() {
      @Override
      public void onResult(ContentsResult result) {
          if (!result.getStatus().isSuccess()) {
              showMessage("Error while trying to create new file contents");
              return;
          }
  
          MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                  .setTitle("testFile.txt")
                  .setMimeType("text/plain")
                  .setStarred(true).build();
          // create a file on root folder
          Drive.DriveApi.getRootFolder(getGoogleApiClient())
                  .createFile(getGoogleApiClient(), changeSet, result.getContents())
                  .setResultCallback(fileCallback);
      }
  };
  
  final private ResultCallback&lt;DriveFileResult&gt; fileCallback = new
          ResultCallback&lt;DriveFileResult&gt;() {
      @Override
      public void onResult(DriveFileResult result) {
          if (!result.getStatus().isSuccess()) {
              showMessage("Error while trying to create the file");
              return;
          }
          showMessage("Created a file: " + result.getDriveFile().getDriveId());
          Log.e("misha", ""+result.getDriveFile().getDriveId() );
      }
  };
  }
  </code></pre>
  
  <p>Then retrieved it's drive ID with quering files by my filne name and printed it to Log :</p>
  
  <pre><code>public class QueryFilesActivity extends BaseDemoActivity {
  
  private ListView mResultsListView;
  private ResultsAdapter mResultsAdapter;
  
  @Override
  protected void onCreate(Bundle b) {
      super.onCreate(b);
      setContentView(R.layout.activity_listfiles);
      mResultsListView = (ListView) findViewById(R.id.listViewResults);
      mResultsAdapter = new ResultsAdapter(this);
      mResultsListView.setAdapter(mResultsAdapter);
  }
  
  /**
   * Clears the result buffer to avoid memory leaks as soon
   * as the activity is no longer visible by the user.
   */
  @Override
  protected void onStop() {
      super.onStop();
      mResultsAdapter.clear();
  }
  
  @Override
  public void onConnected(Bundle connectionHint) {
      super.onConnected(connectionHint);
      Query query = new Query.Builder()
              //.addFilter(Filters.eq(SearchableField.MIME_TYPE, "text/plain"))
          .addFilter(Filters.eq(SearchableField.TITLE, "testFile.txt"))
              .build();
      Drive.DriveApi.query(getGoogleApiClient(), query)
              .setResultCallback(metadataCallback);
  }
  
  final private ResultCallback&lt;MetadataBufferResult&gt; metadataCallback = new
          ResultCallback&lt;MetadataBufferResult&gt;() {
      @Override
      public void onResult(MetadataBufferResult result) {
          MetadataBuffer metaData = result.getMetadataBuffer();
          for (int i = 0 ; i &lt;metaData.getCount(); i++){
              Log.e("misha", metaData.get(i).getDriveId().toString());
          }
          if (!result.getStatus().isSuccess()) {
              showMessage("Problem while retrieving results");
              return;
          }
          mResultsAdapter.clear();
          mResultsAdapter.append(result.getMetadataBuffer());
      }
  };
  }
  </code></pre>
  
  <p>So, I have not\w my file's Drive Id XXXXXXXXXXZiUUxXM0lIUWFhV0pFV0hwSFVqWXhXRzgY9AXXXXXXXXXX. I guess it's correct ID. now when I want to get Contents of file. I get the following error</p>
  
  <p>Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FILE_ID)
                .setResultCallback(idCallback);</p>
  
  <blockquote>
    <blockquote>
      <p>Cannot find DriveId. Are you authorized to view this file?</p>
    </blockquote>
  </blockquote>
  
  <p>I want to get contents of the file, also I want to change the contents and so on. But I stuck at retrieving file contents :( please help guys </p>