我試圖使用Google Docs GData API(.NET)將文件上傳到我的文檔,但我不斷收到引發的錯誤。我找不到任何使用此方法的示例,所以我甚至不確定我是否正確地使用它。使用GData將任何文件上傳到Google文檔
DocumentsService docService = new DocumentsService("MyDocsTest");
docService.setUserCredentials("w****", "*****");
DocumentsListQuery docQuery = new DocumentsListQuery();
DocumentsFeed docFeed = docService.Query(docQuery);
foreach (DocumentEntry entry in docFeed.Entries)
{
Console.WriteLine(entry.Title.Text);
}
Console.ReadKey();
Console.WriteLine();
if (File.Exists(@"testDoc.txt") == false)
{
File.WriteAllText(@"testDoc.txt", "test");
}
docService.UploadDocument(@"testDoc.txt", null); // Works Fine
docService.UploadFile(@"testDoc.txt", null, @"text/plain", false); // Throws Error
上面的代碼將拋出一個GDataRequestException:
Execution of request failed: https://docs.google.com/feeds/default/private/full?convert=false
這是一種aggrivating的,看到這個API可以如此瘋狂的幫助。有誰知道我做錯了什麼?
輝煌,這在https://developers.google.com/gdata/docs/resumable_upload#InitialRequestDotNet上與(幾乎完全相同)樣本一起幫助非常大。我覺得還應該添加另一件事(因爲我無法在任何地方找到任何示例)是,如果您使用OAuth2,則ClientLoginAuthenticator實例需要交換爲OAuth2Authenticator實例。 – 2012-06-09 20:18:50