I've been banging my head all day about this, did a ton of Google searches but to no avail. I am writing an application that downloads all of a user's Google Docs files to local disk. I have to do this for several users, and am only provided with an admin account (to be used via impersonation). The problem only applies to documents that the impersonated user has not authored/shared. In all cases, fetching title information works just fine (irrespective of the author & sharing settings). Downloading files authored by the impersonated account also works fine. However, downloading files authored by other users fails with HTTP 401 or 403 (permission denied). Can someone please tell me what I'm doing wrong? Below is a trimmed version of the code. Thanks!
using System.IO;
using Google.GData.Documents;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.Documents;
void impersonateAndGetAllUsersDocs()
{
string applicationName = "myapp";
string username = "admin@domain.com";
string password = "adminPassword";
string accountToImpersonate = "someOtherUser@domain.com";
DocRequest = new DocumentsRequest(new RequestSettings(applicationName, username, password));
DocumentsListQuery docQuery = new DocumentsListQuery();
docQuery.Uri = new Uri(docQuery.Uri.ToString().Replace("/default/", "/" + accountToImpersonate + "/"));
AtomFeed docFeed = DocRequest.Service.Query(query);
//process every document in the feed
foreach (AtomEntry docEntry in docFeed.Entries)
{
//this line works for all docs (irrespective of who the author is)
string title = docEntry.Title.Text;
Document doc = new Document()
{
AtomEntry = docEntry;
};
//the next line throws an exception with HTTP 401 or 403 (permission) if the author is not the impersonated account
Stream queryStream = DocRequest.Download(doc, Document.DownloadType.html)
//do something with the stream, such as write to local disk
//all done, close the stream
if (queryStream != null)
queryStream.Close();
}
}