嗨,我想使用youtube api创建一个上传视频程序,我想我错过了一些东西。我搜索了一些有关如何使用.net上传的示例,但似乎找不到答案。

这是我的代码:


` 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

昏暗设置为YouTubeRequestSettings
昏暗要求作为YouTubeRequest

设置=新的YouTubeRequestSettings(“youtube上传器”,“AI39si4NwqS3ISLGVjlHBCdC8BfiJJSJWqqcJEvZOLbFohZAslQ4uhgrnFOJKdxGju55g2xoSImzEhXPGE5syMV9X0fh8NEHGText),txtuser。
request =新的YouTubeRequest(设置)

尝试
将newVideo视作视频=新Video()
newVideo.Title =“宿醉样品电影”
newVideo.Tags.Add(New MediaCategory(“Sample”,YouTubeNameTable.CategorySchema))
newVideo.Keywords =“宿醉,有趣”
newVideo.Description =“宿醉”
newVideo.YouTubeEntry.Private = False
newVideo.Tags.Add(新MediaCategory(“宿醉,有趣,喜剧”,YouTubeNameTable.DeveloperTagSchema))

newVideo.YouTubeEntry.Location =新的GeoRssWhere(37,-122)
'或者,您可以只指定一个描述性字符串
'newVideo.YouTubeEntry.setYouTubeExtension(“location”,“Mountain View,CA”);

newVideo.YouTubeEntry.MediaSource =新的MediaFileSource(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)&“\ sample.avi”,“video / avi”)

request.Upload(newVideo)

异常捕获
MsgBox(例如消息)
结束尝试

结束子
最终类(class)

但是会产生此错误执行请求失败https://uploads.gdata.youtube.com/feeds/api/users/default/uploads

最佳答案

我注意到的主要问题是您的代码指定的媒体源为* .avi文件,并为其分配MIME类型为“video / quicktime”。据我所知,QuickTime视频通常以* .mov扩展名表示。当YouTube收到此信息时,很可能会使用转码器将电影内容转换为它自己的本机格式,并会失败,因为它试图使电影看起来像是QuickTime文件一样。您可能应该将MIME类型更改为“video / avi”。

此外,您的示例代码没有调用request.Upload()

关于vb.net - 使用visual basic.net实现Youtube上传,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7866404/

10-12 02:34