Uploading any file with google 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 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.
精彩评论