0
我一直對此感到頭痛,做了大量谷歌搜索,但無濟於事。我正在編寫一個應用程序,將用戶的所有Google Docs文件下載到本地磁盤。我必須爲幾個用戶執行此操作,並且只提供一個管理員帳戶(通過模擬使用)。該問題僅適用於模擬用戶尚未創作/共享的文檔。在所有情況下,獲取標題信息都可以正常工作(不管作者共享設置爲&)。下載由模擬帳戶創作的文件也可以正常工作。但是,下載由其他用戶創作的文件會因HTTP 401或403(權限被拒絕)而失敗。有人可以告訴我我做錯了什麼嗎?以下是代碼的修剪版本。謝謝!Google文檔:無法使用C#中的管理訪問/模擬(禁止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 = "[email protected]";
string password = "adminPassword";
string accountToImpersonate = "[email protected]";
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();
}
}
克勞迪奧 - 非常感謝你的幫助。我能夠進行身份驗證,但是取回流現在會返回一個異常。任何想法? gDataRecirectException.message =執行導致https://www.google.com/accounts/ServiceLogin?service=wise&passive=1209600&continue=https://docs.google.com/feeds/download/spreadsheets/Export?key=重定向 在Google.GData.Client.GDataRequest.Execute() 在Google.GData.Client.GDataGAuthRequest.Execute(的Int32 retryCounter) 在Google.GData.Client.GDataGAuthRequest.Execute() – Isa
PS,這是一個電子表格,並且我包裝了DocumentService:GOAuthRequestFactory requestFactory = new GOAuthRequestFactory(「writely」,applicationName); requestFactory.ConsumerKey = CLIENT_ID; requestFactory.ConsumerSecret = CLIENT_SECRET; // 1-初始化文檔 DocRequest = new DocumentsRequest(new RequestSettings(applicationName)); DocRequest.Service = new DocumentsService(applicationName); DocRequest.Service.RequestFactory = requestFactory; – Isa
爲了下載任何類型的文檔(包括電子表格),您必須確保該應用程序已獲得以下OAuth範圍的授權:https:// docs.google.com/feeds /「https://docs.googleusercontent .com /''https:// spreadsheets.google.com/feeds /' –