1

这是我得到的错误:

An unhandled exception of type 'System.Net.WebException' occurred in Google.GData.Client.dll

Additional information: The request was aborted: The request was canceled.

我将我的代码精简为我正在使用的基本版本:

        YouTubeRequestSettings settings;
        YouTubeRequest request;
        string devkey = "AI39si7VBlJSkNcHUWZdk5OPYa8IXZhVo-ak7KRtFYlfkCdt767P6oxPgoWcMXMfUCLL6-Ot3G-NmLe_cIlCWQDRq2FQl3F0aQ";
        string username = Username.Text;
        string password = Password.Text;
        Upload.Text = "Authenticating...";
        settings = new YouTubeRequestSettings("Music to YouTube", devkey, username, password) { Timeout = -1 };
        request = new YouTubeRequest(settings);

        Video newVideo = new Video();

        newVideo.Title = Title.Text;
        newVideo.Description = Description.Text;
        newVideo.Keywords = Keywords.Text;
        newVideo.Tags.Add(new MediaCategory("Music", YouTubeNameTable.CategorySchema));

        if (Privacy.Text == "Public")
            newVideo.YouTubeEntry.Private = false;
        else if (Privacy.Text == "Unlisted")
            newVideo.YouTubeEntry.AccessControls.Add(new YtAccessControl("list", "denied"));
        else if (Privacy.Text == "Private")
            newVideo.YouTubeEntry.Private = true;

        string fileMusic = "audio";
        string fileImage = "image";
        string fileTimeName = (DateTime.Now.Ticks / 10000).ToString() + ".avi";

        File.Copy(MusicPath.Text, Environment.CurrentDirectory + "\\" + fileMusic, true);
        File.Copy(ImagePath.Text, Environment.CurrentDirectory + "\\" + fileImage, true);

        Upload.Text = "Mixing Music and Image...";
        var mix = Process.Start("ffmpeg.exe", "-loop 1 -r 1 -i " + fileImage + " -i " + fileMusic + " -shortest -vcodec mpeg4 -qscale:v 1 -acodec pcm_alaw -vf scale=\"'iw*max(1280/iw\\,720/ih)':'ih*max(1280/iw\\,720/ih)'\" " + fileTimeName);

        File.Delete(fileMusic);
        File.Delete(fileImage);

        Upload.Text = "Uploading...";

        newVideo.YouTubeEntry.MediaSource = new MediaFileSource(fileTimeName, "video/avi");
        Video createdVideo = request.Upload(newVideo);

        Upload.Text = "Uploaded!";
        File.Delete(fileTimeName);

它在上传请求接近尾声时就失败了,我不知道为什么。上传的最终文件是FFmpeg生成的,我已经测试过,所以上传的文件没有关系,即使大小最多也只有30-40mb。

超时设置为 -1,因此理论上永远不会触发。我唯一能猜到的是身份验证失败。

如果有人有任何经验,我将不胜感激,因为这让我发疯。

4

1 回答 1

0

添加以下代码行,它将解决您的问题。((GDataRequestFactory)request.Service.RequestFactory).Timeout = 9999999; ((GDataRequestFactory)request.Service.RequestFactory).KeepAlive = false;

于 2015-02-28T13:59:58.750 回答