我试图使用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