根据google blog,我可以使用Google API将任何类型的文件上传到我的个人文档(商业帐户已经可以使用)。
但是当我尝试将?convert=false
添加到URI时,我现在收到来自服务的403响应。
我使用此代码(它使用来自SVN trunk的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客户端实际发布/接收服务的内容。
答案 0 :(得分:0)
更新后的文档现在包含一个完整的示例,展示了如何使用ResumableUploader组件上传任何文件:https://developers.google.com/google-apps/documents-list/#uploading_a_new_document_or_file_with_both_metadata_and_content
如果仍然无效,我建议安装Fiddler来捕获HTTP流量并检查请求和响应。