title: Fetching Google Docs Spreadsheet Data using PHP
body: <p>I am trying to fetch the data from a google docs spreadsheet and I think this should work (also seen similar code in another similar question on here) but the response I get is: </p>
  
  <p><code>Moved Temporarily
  The document has moved here.</code> with the link to <code>here</code> being:</p>
  
  <p><code>https://www.google.com/a/4playtheband.co.uk/ServiceLogin?service=wise&amp;continue=https://docs.google.com/a/4playtheband.co.uk/spreadsheet/pub?hl%3Den_US%26hl%3Den_US%26key%3D0AuJb1YSvmVn5dGdvUzU2QUJHUGdaTEZNbVI4dVJ6eHc%26single%3Dtrue%26gid%3D0%26output%3Dcsv%26ndplr%3D1&amp;followup=https://docs.google.com/a/4playtheband.co.uk/spreadsheet/pub?hl%3Den_US%26hl%3Den_US%26key%3D0AuJb1YSvmVn5dGdvUzU2QUJHUGdaTEZNbVI4dVJ6eHc%26single%3Dtrue%26gid%3D0%26output%3Dcsv%26ndplr%3D1&amp;hl=en_US&amp;passive=true&amp;go=true</code></p>
  
  <p>I don't know if the problem is to do with the docs in question being used inside Google Apps but I have set the spreadsheet to be public and I copied the link it provided when I went to <code>Share</code> and exported it as a csv.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;?php
  
  $url='https://docs.google.com/a/4playtheband.co.uk/spreadsheet/pub?hl=en_US&amp;hl=en_US&amp;key=0AuJb1YSvmVn5dGdvUzU2QUJHUGdaTEZNbVI4dVJ6eHc&amp;single=true&amp;gid=0&amp;output=csv';
  
  if (($handle = fopen($url, "r")) !== FALSE)
  {
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
      {
          $totalrows = count($data);
          for ($row=0; $row&lt;=$totalrows; $row++)
          {
              echo $data[$row];
          }
      }
      fclose($handle);
  }
  ?&gt;
  </code></pre>
  
  <p>If it might be an issue I am actually trying to place the fetched data inside a facebox and it seems to be working except for the actual spreadsheet data not appearing since the error message I mentioned earlier actually appears inside the facebox.</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong>
  The code seems to work perfectly fine when the spreadsheet is created within my personal google account and not the account that I use for Google Apps.</p>