0
votes

I'm trying to create a script that backsup all the documents of a user. Everything works fine for text documents but when comes to spreadsheets, the content I have is 401 Unauthorized.

Anyone knows why this is happening?

Here is a bit of code I'm using:

foreach($feeds as $item)
{
    $saveFilePath = $save_path . '/' . $item->getTitle() . "." . $docType["format"];

    $uri = $item->getContent()->getSrc() . "&exportFormat=" . $docType["format"]);;

    $data = $docs
                ->getHttpClient() 
                ->setUri($uri)
                ->request()
                ->getBody();

    $fp = fopen($saveFilePath, "wb");
    fwrite($fp, $data);
    fclose($fp);

}

Thanks

2
my naive assumption would be you are "unauthorized" to do so. Did you check whether the service needs authentication for this action? - Gordon
developers.google.com/google-apps/documents-list/… Cite:"If you received a 401 Unauthorized response, then most likely you did not get your OAuth/AuthSub token with the correct scopes (described above)." - gearsdigital
I assume I am authorized as I can download text documents without problems.... - Vittorio Delsignore
that's fair, but it says the same thing for text documents... - Vittorio Delsignore
I see now. Apparently this is not possible using ClientLogin as http client... - Vittorio Delsignore

2 Answers

0
votes

To download all kind of files from Google Drive using the (deprecated) Documents List API and OAuth as the authorization mechanism you have to request access to all of the following scopes:

https://docs.google.com/feeds/
https://docs.googleusercontent.com/
https://spreadsheets.google.com/feeds/

Even better, you should use the newer Drive API: http://developers.google.com/drive

0
votes

There is an online google example here Lets you experiment with downloading a google file.