在搜索从我的 windows phone 8 应用程序在 youtube 上上传视频的解决方案时,我被带到了YouTube API v2.0 – 直接上传。我跟着文章,编码如下。
private void UploadVideoYoutube(byte[] byteArr, string isoVideoFileName) { Uri uri = new Uri("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"); Dictionary<string, string> post_params = new Dictionary<string, string>(); Dictionary<string, string> extra_headers = new Dictionary<string, string>(); RESTSuccessCallback success_callback = new RESTSuccessCallback(Success); RESTErrorCallback error_callback = new RESTErrorCallback(Error);
try
{
HttpWebRequest request = WebRequest.CreateHttp(uri);
//we could move the content-type into a function argument too.
//request.ContentType = "application/atom+xml; charset=UTF-8";
//request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "video/mp4";
request.Method = "POST";
//provide parameters
post_params.Add("Authorization", "<ClientID>");
//this might be helpful for APIs that require setting custom headers...
if (extra_headers != null)
try
{
foreach (String header in extra_headers.Keys)
request.Headers[header] = extra_headers[header];
}
catch (Exception) { }
request.BeginGetRequestStream((IAsyncResult result) =>
{
HttpWebRequest preq = result.AsyncState as HttpWebRequest;
if (preq != null)
{
Stream postStream = preq.EndGetRequestStream(result);
//allow for dynamic spec of post body
StringBuilder postParamBuilder = new StringBuilder();
if (post_params != null)
foreach (String key in post_params.Keys)
postParamBuilder.Append(String.Format("{0}={1}", key, post_params[key]));
Byte[] requestByteArray = Encoding.UTF8.GetBytes(postParamBuilder.ToString());
//guess one could just accept a byte[] [via function argument] for arbitrary data types - images, audio,...
postStream.Write(requestByteArray, 0, requestByteArray.Length);
postStream.Close();
preq.BeginGetResponse((IAsyncResult final_result) =>
{
HttpWebRequest req = final_result.AsyncState as HttpWebRequest;
if (req != null)
{
try
{
//we call the success callback as long as we get a response stream
WebResponse response = req.EndGetResponse(final_result);
success_callback(response.GetResponseStream());
}
catch (WebException e)
{
//otherwise call the error/failure callback
error_callback(e.Message);
return;
}
}
}, preq);
}
}, request);
}
catch (Exception ex)
{
AppHelper.ErrorOccured(ex);
}
}
但它返回以下错误,请指导我。另外请让我知道是否有任何适用于 Windows 手机的 youtube 库。谢谢
远程服务器返回错误:NotFound。