Java 如何使用YouTube API和MediaStreamSource将视频上载到YouTube
我正在建立一个中继服务,将视频从外部服务器传送到YouTube。目前,我的代码正常工作,但我需要避免在使用MediaFileSource上传到YouTube之前将文件保存在本地。是否有方法传递InputStream而不是文件,并使用MediaStreamSource来允许管道 这样我就可以像这样直接通过管道传输文件Java 如何使用YouTube API和MediaStreamSource将视频上载到YouTube,java,youtube-api,Java,Youtube Api,我正在建立一个中继服务,将视频从外部服务器传送到YouTube。目前,我的代码正常工作,但我需要避免在使用MediaFileSource上传到YouTube之前将文件保存在本地。是否有方法传递InputStream而不是文件,并使用MediaStreamSource来允许管道 这样我就可以像这样直接通过管道传输文件 YouTubeService youTubeService = new YouTubeService("My-Service", developerKey); youTubeS
YouTubeService youTubeService = new YouTubeService("My-Service", developerKey);
youTubeService.setUserCredentials(user, password);
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("Song Title");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Category"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("Test");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("Song Description");
mg.setPrivate(false);
MediaStreamSource ms = new MediaFileSource(new URL("http://www.somewebsite.com/video.mp4").openStream(), "video/mp4");
newEntry.setMediaStream(ms);
String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = youTubeService.insert(new URL(uploadUrl), newEntry);
return createdEntry.getHtmlLink().getHref();
我遇到一个错误,必须将代码编辑为:
String title = "Test Video";
youTubeService.getRequestFactory().setHeader("Slug", title);
我想我应该提一下,因为我没有在你的片段中看到这一点。但是上传要花很长时间。上传有什么进展吗?没有对MediaStreamSource的支持我最终没有使用YouTube API