使用 google api 上传任何文件
根据 Google 博客,我我能够使用谷歌 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 客户端实际从服务发布/接收的内容。
According to google blog I'm able to use google API to upload any kind of file to my personal docs (it was already possible for business accounts).
But right now I've get 403 response from service when I try to add ?convert=false
to URI.
I use this code (it use google-gdata C# api client from SVN trunk)
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());
Without ?convert=false
it works fine.
I appreciate any help: for example how to see what API client actually post / receive from service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新后的文档现在包含一个完整的示例,展示如何使用 ResumableUploader 组件上传任何文件:https://developers.google.com/google-apps/documents-list/#uploading_a_new_document_or_file_with_both_metadata_and_content
如果仍然不起作用,我建议安装 Fiddler 来捕获 HTTP 流量并检查请求和回复。
The updated documentation now includes a complete sample showing how to use the ResumableUploader component to upload any files: https://developers.google.com/google-apps/documents-list/#uploading_a_new_document_or_file_with_both_metadata_and_content
If that still doesn't work, I'd recommend installing Fiddler to capture the HTTP traffic and inspect the request and response.