0

根据谷歌博客,我可以使用谷歌 API 将任何类型的文件上传到我的个人文档(企业帐户已经可以)。

但是现在,当我尝试添加?convert=false到 URI 时,我得到了来自服务的 403 响应。

我使用此代码(它使用来自 SVN 中继的 google-gdata C# api 客户端)

int CHUNK_SIZE = 1;

ClientLoginAuthenticator cla = new ClientLoginAuthenticator("uploader", ServiceNames.Documents, "username", "password");

// Set up resumable uploader and notifications
ResumableUploader ru = new ResumableUploader(CHUNK_SIZE);
ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(ru_AsyncOperationCompleted);
ru.AsyncOperationProgress += new AsyncOperationProgressEventHandler(ru_AsyncOperationProgress);

// Set metadata for our upload.
Document entry = new Document();
entry.Title = "test file";
entry.MediaSource = new MediaFileSource(fileName, "application/msword");

// Add the upload uri to document entry.
Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false");
AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);
link.Rel = ResumableUploader.CreateMediaRelation;
entry.DocumentEntry.Links.Add(link);

ru.InsertAsync(cla, entry.DocumentEntry, new object());

没有?convert=false它工作正常。

我感谢任何帮助:例如如何查看 API 客户端实际从服务发布/接收的内容。

4

1 回答 1

0

更新后的文档现在包含一个完整的示例,展示了如何使用 ResumableUploader 组件上传任何文件:https ://developers.google.com/google-apps/documents-list/#uploading_a_new_document_or_file_with_both_metadata_and_content

如果这仍然不起作用,我建议安装 Fiddler 以捕获 HTTP 流量并检查请求和响应。

于 2012-05-27T03:16:19.167 回答