1

我有关于上传文件到 Youtube 的问题

调查网页后,我找到了链接https://developers.google.com/youtube/2.0/developers_guide_protocol_direct_uploading#Sending_a_Direct_Upload_API_Request 并有一些发现可以实现上传。但现在我遇到了如下问题列表:

httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + access_token);
httpClient.DefaultRequestHeaders.Add("GData-Version", "2.0");
httpClient.DefaultRequestHeaders.Add("X-GData-Key", "key=" + clientID);
httpClient.DefaultRequestHeaders.Add("Slug", "video.wav");
//httpClient.DefaultRequestHeaders.Add("Content-Type", "multipart/related; boundary=\"f93dcbA3\"");
httpClient.DefaultRequestHeaders.Add("Content-Length", "4141440");
httpClient.DefaultRequestHeaders.Add("Connection", "close");

它会发生异常,其原因是

误用的标头名称。确保请求标头与 HttpRequestMessage 一起使用,响应标头与 HttpResponseMessage 一起使用,内容标头与 HttpContent 对象一起使用。

所以我改变了方式

var requset = new HttpRequestMessage( new HttpMethod("post"), "https://gdata.youtube.com//feeds/api/users/default/subscriptions");

requset.Headers.Add("Host", "gdata.youtube.com");

requset.Headers.Add("Authorization", "Bearer " + access_token);

requset.Headers.Add("GData-Version", "2.0");

requset.Headers.Add("X-GData-Key", "key=" + simpleKey);
string str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\"> <category scheme=\"http://gdata.youtube.com/schemas/2007/subscriptiontypes.cat\" term=\"channel\"/> <yt:username>GoogleDevelopers</yt:username></entry>";

StringContent cnt = new StringContent(str);

cnt.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/atom+xml");

cnt.Headers.ContentLength = 270;

但是仍然没有任何效果,有人可以给我一些提示吗?

非常感谢

标记

4

0 回答 0