使用 google api 上传任何文件

发布于 2024-11-05 19:53:56 字数 1468 浏览 0 评论 0原文

根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反差帅 2024-11-12 19:53:56

更新后的文档现在包含一个完整的示例,展示如何使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文