title: Google Drive API: check if folder exists
body: <p>I'm using the Google Drive API to try to answer a seemingly simple question: does a folder by a certain name exist in a drive?</p>
  
  <p>Specifics:</p>
  
  <ul>
  <li>Version V3 of the drive API</li>
  <li>Python client: <code>googleapiclient</code></li>
  </ul>
  
  <p>Example:</p>
  
  <p>Given the enclosing drive ID <code>abcdef</code>, does the folder with name <code>June 2019</code> (and mimeType <code>application/vnd.google-apps.folder</code>) exist?</p>
  
  <p>Current route:</p>
  
  <pre><code>&gt;&gt;&gt; from googleapiclient.discovery import build
  &gt;&gt;&gt; # ... build credentials
  &gt;&gt;&gt; driveservice = build("drive", "v3", credentials=cred).files()
  &gt;&gt;&gt; [i for i in driveservice.list().execute()['files'] if 
  ...  i['name'] == 'June 2019' and i['mimeType'] == 'application/vnd.google-apps.folder']                                                                                                                                                                     
  [{'kind': 'drive#file',
    'id': '1P1k5c2...........',
    'name': 'June 2019',
    'mimeType': 'application/vnd.google-apps.folder'}]
  </code></pre>
  
  <p>So the answer is yes, the folder exists.  But there should be a more efficient way to do this <a href="https://developers.google.com/drive/api/v3/reference/files/list" rel="noreferrer">via <code>.list()</code></a> by passing the <code>driveId</code>.  How can that be done?  I've tried various combinations all of which seem to throw a non-200 response.</p>
  
  <pre><code>&gt;&gt;&gt; FOLDER_ID = "abcdef........"
  &gt;&gt;&gt; driveservice.list(corpora="drive", driveId=FOLDER_ID).execute()                                                                                                                                                                                                          
  # 403 response, even when adding the additional requested params
  </code></pre>
  
  <p>How can I use the <code>q</code> param to query by folder name?</p>