我正在制作一个用于将视频上传到 Youtube 的 POC ASP.NET MVC 应用程序。当我尝试上传视频时,我得到一个GDataRequestException
内部WebException
异常。这是我收到的信息:
(500) Internal Server Error.
The stacktrace of the WebException is:
at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.GDataRequest.Execute()
这是我的代码:
public ActionResult oauth2callback(string code)
{
if (!string.IsNullOrWhiteSpace(code))
{
JObject json;
NameValueCollection postData = new NameValueCollection();
postData.Add("code", code);
postData.Add("client_id", "The client ID");
postData.Add("client_secret", "The secret code");
postData.Add("redirect_uri", "http://localhost:64896/home/oauth2callback");
postData.Add("grant_type", "authorization_code");
json = JObject.Parse(
HttpClient.PostUrl(
new Uri("https://accounts.google.com/o/oauth2/token"), postData));
string accessToken = json["access_token"].ToString();
string refreshToken = json["refresh_token"].ToString();
bool isBearer =
string.Compare(json["token_type"].ToString(),
"Bearer",
true,
CultureInfo.CurrentCulture) == 0;
var settings = new YouTubeRequestSettings("App name",
"API key from simple API access", accessToken);
var request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "Test Video";
newVideo.Keywords = "key 1 , key 2";
newVideo.Tags.Add(new MediaCategory("Games", YouTubeNameTable.CategorySchema));
newVideo.Description = "Upload testing";
newVideo.YouTubeEntry.Private = false;
newVideo.Private = true;
newVideo.YouTubeEntry.MediaSource = new
MediaFileSource(@"C:\Users\Kaare\Videos\TestVideo1.avi", "video/x-msvideo");
try
{
Video createdVideo = request.Upload(newVideo);
return View();
}
catch (GDataRequestException exp)
{
//Do something mening full
}
}
else
{
return RedirectToAction("LoginFail");
}
}
你们中的任何人都知道出了什么问题吗?