用java将视频上传到youtube
我的本地磁盘上有一个视频,我想通过我的应用程序上传到youtube上。你能给我同样的指导方针吗。请为我提供执行该操作的步骤或代码或链接。 提前谢谢 在解决方案提出后,我尝试了: gdata.youtube.com/feeds/api/users/users/uploads(用户作为某个用户名),但我收到IOException。即,与服务通信时出现问题用java将视频上传到youtube,java,jsp,servlets,youtube-api,Java,Jsp,Servlets,Youtube Api,我的本地磁盘上有一个视频,我想通过我的应用程序上传到youtube上。你能给我同样的指导方针吗。请为我提供执行该操作的步骤或代码或链接。 提前谢谢 在解决方案提出后,我尝试了: gdata.youtube.com/feeds/api/users/users/uploads(用户作为某个用户名),但我收到IOException。即,与服务通信时出现问题 java.net.SocketException: Connection reset java.net.SocketInputStream.
java.net.SocketException: Connection reset
java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:641)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:589)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1319)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:490)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:470)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:534)
at com.google.gdata.client.media.MediaService.insert(MediaService.java:353)
at ytupload.YouTubeWriteClient.uploadVideo(YouTubeWriteClient.java:508)
at ytupload.YouTubeWriteClient.main(YouTubeWriteClient.java:828)
Plz帮助…您是否查看了《谷歌开发者指南》中的“查看”部分?你会发现这样的东西:
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("My Test Movie");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("cars");
mg.getKeywords().addKeyword("funny");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("My description");
mg.setPrivate(false);
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
// alternatively, one could specify just a descriptive string
// newEntry.setLocation("Mountain View, CA");
MediaFileSource ms = new MediaFileSource(new File("file.mov"), "video/quicktime");
newEntry.setMediaSource(ms);
String uploadUrl =
"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
在上传视频之前,您可能会成功进行身份验证,如:
YouTubeService service = new YouTubeService(clientID, developer_key);
希望这有帮助您必须创建一个新的
VideoEntry
对象
以下代码上载视频:
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("Title goes here");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("keyword-here");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("My description");
mg.setPrivate(false);
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
// alternatively, one could specify just a descriptive string
// newEntry.setLocation("Mountain View, CA");
MediaFileSource ms = new MediaFileSource(new File("file.mov"), "video/quicktime");
newEntry.setMediaSource(ms);
String uploadUrl =
"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
请参见当我尝试访问此url(用户作为某个用户名)时,它显示为未找到,但如果我访问(用户作为某个用户名),则会显示一些xml。。所以我不知道该使用哪个url。建议。我已经尝试了你告诉我的…我在上面发布了一些错误…请提出建议…你安装了谷歌数据客户端库了吗?我自己没有运行代码,但它似乎在网站上有很好的文档记录,您遇到了什么错误?为什么不浏览文档: