私はこれについて一日中頭を悩ませており、大量のGoogle検索を行いましたが、役に立ちませんでした. ユーザーのすべての Google ドキュメント ファイルをローカル ディスクにダウンロードするアプリケーションを作成しています。複数のユーザーに対してこれを行う必要があり、管理者アカウントのみが提供されます(偽装で使用されます)。この問題は、偽装されたユーザーが作成または共有していないドキュメントにのみ適用されます。いずれの場合も、タイトル情報の取得は問題なく機能します (作成者や共有設定に関係なく)。偽装されたアカウントによって作成されたファイルのダウンロードも正常に機能します。ただし、他のユーザーが作成したファイルのダウンロードは、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();
}
}