title: Google drive API shareable link for public
body: <p>I am using Google Drive API in Laravel 5.2. I am able to give access for a file to a particular email ID of Gmail. However, I want to give access publicly for all who ever have the file link.</p>
  
  <p>I have tried this <code>webViewLink</code>, <code>alternateLink</code> and <code>webContentLink</code>, but all these are blank.</p>
  
  <p>See Image output of file object</p>
  
  <p><a href="https://i.stack.imgur.com/nQuw6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nQuw6.png" alt="enter image description here"></a></p>
  
  <pre><code>    if(isset($options['name']) &amp;&amp; isset($options['path'])){
          $auth_con = new AuthController();
          $client = $auth_con-&gt;getClient();
          $service = new \Google_Service_Drive($client);
          $fileMetadata = new \Google_Service_Drive_DriveFile(array(
              'name' =&gt; $options['name']));
          $content = file_get_contents($options['path']);
          $file = $service-&gt;files-&gt;create($fileMetadata, array(
              'data' =&gt; $content,
              'uploadType' =&gt; 'multipart',
              'fields' =&gt; 'id'
          ));
          $file_id = $file-&gt;id;
          if(isset($options['to'])){
              foreach ($options['to'] as $key =&gt; $value) {
                  drive_permission($service, $value, $file_id);
              }
          }
       }
  
  
      function drive_permission($service, $email_id, $file_id)
      {
        $service-&gt;getClient()-&gt;setUseBatch(true);
        try {
          $batch = $service-&gt;createBatch();
  
          $userPermission = new Google_Service_Drive_Permission(array(
              'type' =&gt; 'group',
              'role' =&gt; 'reader',
              'emailAddress' =&gt; $email_id
          ));
          $request = $service-&gt;permissions-&gt;create(
              $file_id, $userPermission, array('fields' =&gt; 'id'));
          $batch-&gt;add($request, 'anyone');
          $results = $batch-&gt;execute();
        } finally {
          $service-&gt;getClient()-&gt;setUseBatch(false);
      }
  }
  </code></pre>