开发者

Uploading any file with google api

开发者 https://www.devze.com 2023-03-05 06:41 出处:网络
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).

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 notific开发者_如何学Goations
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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号