title: Download Google Docs Spreadsheet via PHP
body: <p>I'm trying to download and parse a google spreadsheet directly via PHP.
  Do i need to download the exported CSV file from google docs a different way?</p>
  
  <pre><code>$csv = file_get_contents('https://docs.google.com/spreadsheets/d/KEY/export?format=csv');
  print_r($csv);
  </code></pre>
  
  <p>I tried it with file too:</p>
  
  <pre><code>$csv = file('https://docs.google.com/spreadsheets/d/KEY/export?format=csv');
  </code></pre>
  
  <p>And with cURL</p>
  
  <pre><code>$ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL, "https://docs.google.com/spreadsheets/d/KEY/export?format=csv"); 
  curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
  curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  
  $csv = curl_exec($ch); 
  curl_close($ch);
  var_dump($csv);
  </code></pre>
  
  <p>When i call the URL from a browser i get a nice tiny CSV file. This way i get the source of the google docs website.</p>