【问题标题】:How to fix Connection Reset Exception in java?如何修复java中的连接重置异常?
【发布时间】:2012-11-03 18:21:22
【问题描述】:

我正在尝试将视频上传到 youtube: 我的代码是:

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)

我从 main 调用的函数。上传(服务); 其中 service = new YouTubeService(clientId,developerKey); 我该如何修复这个错误?我浪费了一天的时间..但无法弄清楚。请提出建议。

编辑: VIDEO_UPLOAD_FEED ="http://gdata.youtube.com/feeds/api/users/abc123/uploads"

如果我想将视频文件的路径作为一些 http url 给出呢? 请建议。 提前感谢

【问题讨论】:

    标签: java youtube youtube-api


    【解决方案1】:

    您是否在服务上成功设置了用户凭据?它可能用于创建与服务器的连接。

    service.setUserCredentials(User, Password);
    

    看看this

    【讨论】:

    • 是的,我已经设置了 service.setcredentials(user,password);
    • 我怀疑用户是 abc@gmail.com,密码是我们登录 youtube 的密码吗?
    • 它必须是一个有效的 googke 帐户。
    猜你喜欢
    • 2019-05-26
    • 2019-06-13
    • 2014-09-18
    • 1970-01-01
    • 2021-12-23
    • 2012-10-29
    • 2018-10-07
    • 2015-08-17
    • 1970-01-01
    相关资源
    最近更新 更多