Hi Eric,

Thanks for the reply. I'm not trying to download a spreadsheet. I also
changed the feed URI to the correct one. However when I echo out the
content, I still get the login page? This feels like some
authentication issue. I copied your code verbatim, and tried many
other tricks to get the file to download directly to the server using
file_get_contents() followed by file_put_contents(). However, I keep
getting a file containing the login page rather than the file I want.
I can correctly retrieve everything else about the file, such as the
name of the file, the link etc.

Another observation is that when I copy and paste the file url I get
from the response header and put that directly into browser address
bar, I get the prompt to download the file without the login page.
However, when I try to file_get_contents from that same url, I get the
login page again. Could it be something wrong with the $opts array or
session token?

Thanks,
Fan

On Jul 22, 2:20 pm, "Eric (Google)" <api.e...@google.com> wrote:
> Are you trying to download a spreadsheet?  If so,
> be sure to also obtain an AuthSub token good 
> forhttp://spreadsheets.google.com/feeds.
>
> Also, there's a mistake in that snippet I posted.
> The feed URI should be
> 'http://docs.google.com/feeds/documents/private/full/-/document'
>
> Eric
>
> On Jul 22, 6:00 am, faninator <fanina...@gmail.com> wrote:
>
> > Hi Eric,
>
> > I tried your method of using file_get_contents with the example code
> > that you posted but I was unable to download the file to the server.
> > If I echo the result from the download function, I get a broken google
> > login page and then a prompt for download. However, when I'm trying to
> > write the file content to a new file on my server (which is my
> > ultimate goal here), it writes the google login page into the file. Do
> > you know what could be causing the problem?
>
> > Thanks,
> > Fan
>
> > On Jul 15, 4:32 pm, "Eric (Google)" <api.e...@google.com> wrote:
>
> > > Posted a tip on 
> > > this:http://gdatatips.blogspot.com/2009/07/download-google-doc-using-php-l...
>
> > > On Jul 15, 1:13 pm, "Eric (Google)" <api.e...@google.com> wrote:
>
> > > > Hi,
>
> > > > You should be using the <entry>'s content src link
> > > > and not the alternate (/View?docID=...) link that
> > > > points to Google Docs.  Having said that,
> > > > you'll need to write a download method yourself
> > > > b/c the Zend_Gdata_Docs component doesn't contain
> > > > this latest API feature.
>
> > > > Here's how you _could_ use file_get_contents() to
> > > > export a doc as a .txt file.  Note: to export
> > > > spreadsheets, you'll need a valid AuthSub session
> > > > token for scope=http://spreadsheets.google.com/feeds/
> > > > as well.
>
> > > > $feed = $gdClient->getDocumentListFeed(
> > > >   'http://docs.google.com/feeds/documents/private/full/-document');
>
> > > > // download first entry
> > > > $contentLink = $feed->entries[0]->content->getSrc();
> > > > $fileContents = download($gdClient, $contentLink, 'txt');
>
> > > > echo 'Contents of document "' . $feed->entries[0]->title . '":<hr>';
> > > > echo "<pre>$fileContents</pre>";
>
> > > > function download($client, $url, $format=null) {
> > > >   $token = $client->getHttpClient()->getAuthSubToken();
> > > >   $opts = array(
> > > >     'http' => array(
> > > >       'method' => "GET",
> > > >       'header' => "GData-Version: 2.0\r\n".
> > > >                   "Authorization: AuthSub token=\"$token\"\r\n"
> > > >     )
> > > >   );
> > > >   $context = stream_context_create($opts);
>
> > > >   if ($url != null) {
> > > >     $url =  $url . "&exportFormat=$format";
> > > >   }
>
> > > >   return file_get_contents($url, false, $context);
>
> > > > }
>
> > > > Eric
>
> > > > On Jul 14, 7:56 pm, infinitas <john.cia...@gmail.com> wrote:
>
> > > > > $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
> > > > > $httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
> > > > > $service);
> > > > > $gdClient = new Zend_Gdata_Docs($httpClient);
> > > > > echo file_get_contents("http://docs.google.com/View?docID={$id}
> > > > > &revision=_latest&hgd=1");
>
> > > > > More or less, this is what I have *working* which raises three
> > > > > questions.
>
> > > > > 1. Is fopen/curl/file_get_contents the accepted method of getting the
> > > > > content or is there an API call I should be using?
> > > > > 2. Does the document HAVE to be "published" for it to work?
> > > > > 3. Is it necessary to have the "Google Docs -- Web word processing,
> > > > > presentations and spreadsheets." in the footer? (I am assuming number
> > > > > one is "no" and the correct method would probably have an option for
> > > > > this).
>
> > > > > On Jul 14, 12:11 am, Eric Bidelman <api.e...@google.com> wrote:
>
> > > > > > What have you tried?
>
> > > > > > On Mon, Jul 13, 2009 at 7:53 PM, infinitas <john.cia...@gmail.com> 
> > > > > > wrote:
>
> > > > > > > I am using the PHP Zend_Gdata API. I have successfully been able 
> > > > > > > to
> > > > > > > retrieve a list of my documents and search through my documents, 
> > > > > > > but I
> > > > > > > have not been able to retrieve the actual content inside a 
> > > > > > > document.
> > > > > > > Could someone please point me in the right direction?
>
> > > > > > > Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Docs Data APIs" group.
To post to this group, send email to Google-Docs-Data-APIs@googlegroups.com
To unsubscribe from this group, send email to 
google-docs-data-apis+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Docs-Data-APIs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to