2
我試圖將視頻上傳到YouTube: 我對相同的代碼是:如何解決在java中的連接重置異常?
private static void uploadVideo(YouTubeService service) throws IOException {
System.out.println("First, type in the path to the movie file:");
File videoFile = new File(readLine());
if (!videoFile.exists()) {
System.out.println("Sorry, that video doesn't exist.");
return;
}
System.out.println(
"What is the MIME type of this file? (ex. 'video/quicktime' for .mov)");
String mimeType = readLine();
System.out.println("What should I call this video?");
String videoTitle = readLine();
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Entertainment"));
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent(videoTitle);
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("gdata-test");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent(videoTitle);
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));
MediaFileSource ms = new MediaFileSource(videoFile, mimeType);
newEntry.setMediaSource(ms);
try {
service.insert(new URL(VIDEO_UPLOAD_FEED), newEntry);
} catch (ServiceException se) {
System.out.println("Sorry, your upload was invalid:");
System.out.println(se.getResponseBody());
return;
}
System.out.println("Video uploaded successfully!");
}
switch(uploader.getUploadState()) {
case COMPLETE:
output.println("Uploaded successfully");
break;
case CLIENT_ERROR:
output.println("Upload Failed");
break;
default:
output.println("Unexpected upload status");
break;
}
}
當我運行這個它顯示了異常:
java.net.SocketException: Connection reset
at 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:514)
at ytupload.YouTubeWriteClient.main(YouTubeWriteClient.java:837)
我從主調用函數。上傳(服務); 其中service = new YouTubeService(clientId,developerKey); 我該如何解決這個錯誤?我浪費了一天的時間......但沒有想到。請建議。
編輯: VIDEO_UPLOAD_FEED =「http://gdata.youtube.com/feeds/api/users/abc123/uploads」
如果視頻文件的路徑我想給一些HTTP URL是什麼? 請建議。 Thanx提前
亞我已經設置service.setcredentials(用戶,密碼)
採取alook; – Vaibs
我懷疑用戶會有一些[email protected]和密碼wis我們登錄到youtube的權利? – Vaibs
它必須是一個有效的googke帳戶。 – CloudyMarble