问题
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?:
回答1:
You should use the latest Client Library for .NET and check the example how to upload video
回答2:
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)
来源:https://stackoverflow.com/questions/26142771/upload-video-to-youtube-execution-of-request-failed-401-unauthorized