使用 Visual Basic.net 实现 Youtube 上传
你好,我想使用 youtube api 创建一个上传视频程序,我想我错过了一些东西。我搜索了一些有关如何使用 .net 上传的示例,但似乎找不到答案。
这是我的代码:
` 导入 Google.YouTube 导入 Google.GData.Client 导入 Google.GData.Extensions 导入 Google.GData.Extensions.MediaRss 导入 Google.GData.YouTube 将 Google.GData.Extensions.Location
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim 设置导入为 YouTubeRequestSettings 暗淡请求作为 YouTubeRequest
设置 = 新 YouTubeRequestSettings("youtube uploader", "AI39si4NwqS3ISLGVjlHBCdC8BfiJJSJWqqcJEvZOLbFohZAslQ4uhgrnFOJKdxGju55g2xoSImzEhXPGE5syMV9X0fh8NEHGg", txtuser.Text, txtpass.Text) request = New YouTubeRequest(settings)
Try Dim newVideo As Video = New Video() newVideo.Title = "Hangover Sample Movie" newVideo.Tags.Add(New MediaCategory("Sample", YouTubeNameTable.CategorySchema)) newVideo.Keywords = "hangover, funny" newVideo.Description = "Hangover" newVideo.YouTubeEntry.Private = False newVideo.Tags.Add(New MediaCategory("hangover, funny, comedy", YouTubeNameTable.DeveloperTagSchema)) newVideo.YouTubeEntry.Location = New GeoRssWhere(37, -122) ' alternatively, you could just specify a descriptive string ' newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA"); newVideo.YouTubeEntry.MediaSource = New MediaFileSource(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\sample.avi", "video/avi") request.Upload(newVideo) Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class`
但会产生此错误 执行请求失败 https ://uploads.gdata.youtube.com/feeds/api/users/default/uploads
Hi i want to create an uploading video program using youtube api I think I missed something. I search for some examples on how to upload using .net but cant seem to find an answer.
Heres my code:
` Imports Google.YouTube Imports Google.GData.Client Imports Google.GData.Extensions Imports Google.GData.Extensions.MediaRss Imports Google.GData.YouTube Imports Google.GData.Extensions.Location
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim settings As YouTubeRequestSettings
Dim request As YouTubeRequest
settings = New YouTubeRequestSettings("youtube uploader", "AI39si4NwqS3ISLGVjlHBCdC8BfiJJSJWqqcJEvZOLbFohZAslQ4uhgrnFOJKdxGju55g2xoSImzEhXPGE5syMV9X0fh8NEHGg", txtuser.Text, txtpass.Text)
request = New YouTubeRequest(settings)
Try
Dim newVideo As Video = New Video()
newVideo.Title = "Hangover Sample Movie"
newVideo.Tags.Add(New MediaCategory("Sample", YouTubeNameTable.CategorySchema))
newVideo.Keywords = "hangover, funny"
newVideo.Description = "Hangover"
newVideo.YouTubeEntry.Private = False
newVideo.Tags.Add(New MediaCategory("hangover, funny, comedy", YouTubeNameTable.DeveloperTagSchema))
newVideo.YouTubeEntry.Location = New GeoRssWhere(37, -122)
' alternatively, you could just specify a descriptive string
' newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
newVideo.YouTubeEntry.MediaSource = New MediaFileSource(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\sample.avi", "video/avi")
request.Upload(newVideo)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class`
but it produces this error Execution of request failed https://uploads.gdata.youtube.com/feeds/api/users/default/uploads
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我注意到的主要问题是您的代码指定了 *.avi 文件形式的媒体源,并为其分配了“video/quicktime”的 MIME 类型。据我所知,QuickTime 视频通常以 *.mov 扩展名表示。当 YouTube 收到此信息时,它可能会使用转码器将您的电影内容转换为其自己的本机格式,但会失败,因为它试图将电影视为 QuickTime 文件。您可能应该将 MIME 类型更改为“video/avi”。
此外,您的示例代码未调用
request.Upload()
。The primary problem I'm noticing is that your code is specifying a media source that is a *.avi file and assigning it a MIME type of "video/quicktime." So far as I am aware, QuickTime videos are commonly indicated by *.mov extension. When YouTube receives this information, it is likely to use a transcoder to turn your movie content into its own native format and failing because it is attempting to make sense of the movie as if it were a QuickTime file. You should probably change the MIME type to "video/avi".
Additionally, your sample code is not calling
request.Upload()
.首先想到的是,您在初始化时创建一个请求对象,但在单击按钮之前不会使用它。这可能是一个问题,我看到的 C# 示例相继执行了这些操作。
但最相似的问题是,您似乎正在使用表单控件为设置对象设置一些值,并在表单初始化时执行此操作,而此类控件通常没有可用的值。如果您将值硬编码到控件中,最好只对设置对象这样做。如果您没有在设计时将值硬编码到控件中,那么这可能是您的问题(这与您的身份验证错误非常吻合)。
The first thing that comes to mind is that you are creating a request object at initialization, but not using it until a button is clicked. This might be a problem, the C# example I saw for this did them one after the other.
But the most like problem is that you seem to be setting some values for the setting object using form controls, and doing this at form initialization time, where such controls generally don't have usable values. If you're hard coding values into the controls, it would be better to just do so for the setting object. If you're not hard coding the values into your control at design time, then that's probably your problem (which fits in nicely with your authentication error).
我刚刚发现我的代码的问题是 youtube 没有问我用户名(但我确实有我的 youtube 帐户,疯狂...XD)...然后我再次尝试了代码并且它有效。还要感谢@jmoreno。
I just found out that the problem with my code is that youtube havent asked me a username(but i do have my youtube account, crazy... XD)...then i tried again the code and it works. thanks also to @jmoreno.