Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Google Docs: Cannot export/download user's document using administrative access/impersonation (forbidden 403) in C#
- 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();
- }
- }
Add Comment
Please, Sign In to add comment