4

I have a video in my local disk i want to upload it on youtube through my application. Can you give me the guidelines to follow the same. please gve me steps to perform that or code or links. Thanks in advance.

After the solution suggested i tried with: gdata.youtube.com/feeds/api/users/users/uploads (with users as some username) but i am getting IOException.i.e There was a problem communicating with the service.

  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 help...

4

2 に答える 2

4

Google 開発者ガイドのYoutube APIを確認しましたか、動画のアップロードセクションを確認しましたか? 次のようなものが見つかります。

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);

お役に立てれば

于 2012-11-13T09:05:57.537 に答える
1

新しい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);

https://developers.google.com/youtube/2.0/developers_guide_java#Uploading_Videosを参照してください

于 2012-11-13T09:06:57.660 に答える