title: How to share file for anyone Google Drive API using PHP
body: <p>I have been trying over and over, but could not reach any result.
  the code is generating permission id and I don't know what that means.</p>
  
  <p>Please do help if anyone succeeded in this before, I just want to share file publicly using the google drive api v2.0</p>
  
  <pre><code>$fileId = '18mWN0UWX_z-4A1gag85ou0Im-wvKfMZU-tibdVd8nxY';
  $userPermission = new Google_Service_Drive_Permission(array(
      'type' =&gt; 'anyone',
      'role' =&gt; 'reader',
      'emailAddress' =&gt; 'user@example.com'
    ));
  
    $request = $service-&gt;permissions-&gt;create(
      $fileId, $userPermission, array('fields' =&gt; 'id'));
    $batch-&gt;add($request, 'user');
    $domainPermission = new Google_Service_Drive_Permission(array(
      'type' =&gt; 'domain',
      'role' =&gt; 'reader',
      'domain' =&gt; 'example.com'
    ));
  
    $request = $service-&gt;permissions-&gt;create(
      $fileId, $domainPermission, array('fields' =&gt; 'id'));
    $batch-&gt;add($request, 'domain');
    $results = $batch-&gt;execute();
  
    foreach ($results as $result) {
      if ($result instanceof Google_Service_Exception) {
        // Handle error
        printf($result);
      } else {
        printf("Permission ID: %s\n", $result-&gt;id);
      }
    }
  } finally {
    $service-&gt;getClient()-&gt;setUseBatch(false);
  }
  </code></pre>