我整天都在为此头疼,做了很多谷歌搜索,但无济于事。我正在编写一个将用户的所有 Google Docs 文件下载到本地磁盘的应用程序。我必须为多个用户执行此操作,并且只提供一个管理员帐户(通过模拟使用)。该问题仅适用于模拟用户尚未创作/共享的文档。在所有情况下,获取标题信息都可以正常工作(无论作者和共享设置如何)。下载由模拟帐户创作的文件也可以正常工作。但是,下载由其他用户创作的文件会失败,并出现 HTTP 401 或 403(权限被拒绝)。有人可以告诉我我做错了什么吗?下面是代码的精简版本。谢谢!
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();
}
}