Upload video to YouTube, Execution of request fail

2019-07-27 09:55发布

I am trying to upload unlisted videos to my youtube account, i continue to get errors which i can't resolve. The YouTube Data Api 3 is does not support any .Net currently as far as i can see, and during my two day search for answers i see people with the most success have used the Google GData.

Below is my attempt at GData trying to post a YouTube video.

Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Reflection
Imports System.Threading
Imports System.Threading.Tasks

Imports Google.GData.Client
Imports Google.GData.Extensions
Imports Google.GData.YouTube
Imports Google.GData.Extensions.MediaRss
Imports Google.YouTube

Sub DirectUpload()

        Dim APIkey As String = "MyKey"
        Dim Path As String = "c://Users/Shaun/Desktop/TestVid/test.mp4"
        Dim Title = "My Test Movie1"

        Dim settings As New YouTubeRequestSettings("Uploader", APIkey)
        settings.Timeout = 60 * 60 * 1000
        Dim request As New  YouTubeRequest(settings)

        Dim service As New YouTubeService("Uploader", APIkey)
        DirectCast(request.Service.RequestFactory, GDataRequestFactory).Timeout = 9999999
        DirectCast(service.RequestFactory, GDataRequestFactory).KeepAlive = False

        Dim newVideo As New Video()

        newVideo.Title = Title
        newVideo.Tags.Add(new MediaCategory("People & Blogs", YouTubeNameTable.CategorySchema))
        newVideo.Keywords = "Halls"
        newVideo.Description = "Halls-" + Title
        newVideo.YouTubeEntry.Private = true
        'newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag", YouTubeNameTable.DeveloperTagSchema))
        newVideo.YouTubeEntry.MediaSource = new MediaFileSource(Path,"video/quicktime")

        dim createdVideo As Video = request.Upload(newVideo)
        'Success

End Sub

I get the following error messages:

Execution of request failed: https://uploads.gdata.youtube.com/feeds/api/users/default/uploads

The remote server returned an error: (401) Unauthorized.

I assume this has to be user permitions as its Unauthorized. I have created a product and user the Developer Key provided so?:

enter image description here

2条回答
小情绪 Triste *
2楼-- · 2019-07-27 10:13

Every Google Account is blocked for unknown applications access.
Maybe you have got the e-mail from Google security team about unknown activity.
Need to log in and grant access for unknown applications at Google account security settings (https://www.google.com/settings/u/1/security/lesssecureapps)

查看更多
霸刀☆藐视天下
3楼-- · 2019-07-27 10:14

You should use the latest Client Library for .NET and check the example how to upload video

查看更多
登录 后发表回答