Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从Youtube视频源获取超过999条结果?_Java_Video_Youtube_Youtube Api_Feed - Fatal编程技术网

Java 如何从Youtube视频源获取超过999条结果?

Java 如何从Youtube视频源获取超过999条结果?,java,video,youtube,youtube-api,feed,Java,Video,Youtube,Youtube Api,Feed,我现在正在写一篇关于长尾的文章,希望获得数据来研究长尾的行为。这就是为什么我想检索youtube视频的浏览量信息。唯一的问题是,像“最受欢迎”这样的特定主题的一个视频提要只有999个条目。是否有一种方法可以将更多数据检索到特定类别或一般类别?我将在此处发布我当前的代码(这是一次尝试检索“sports”类别数据的尝试): 999项似乎是设计上的限制。见: “API返回视频源以响应搜索视频的请求。视频源最多包含999个条目。” 看起来同样的限制也适用于该网站 您可以尝试添加以限制获得的结果数量,例如

我现在正在写一篇关于长尾的文章,希望获得数据来研究长尾的行为。这就是为什么我想检索youtube视频的浏览量信息。唯一的问题是,像“最受欢迎”这样的特定主题的一个视频提要只有999个条目。是否有一种方法可以将更多数据检索到特定类别或一般类别?我将在此处发布我当前的代码(这是一次尝试检索“sports”类别数据的尝试):


999项似乎是设计上的限制。见:

“API返回视频源以响应搜索视频的请求。视频源最多包含999个条目。”

看起来同样的限制也适用于该网站

您可以尝试添加以限制获得的结果数量,例如:

  • 标题=真|假
  • 持续时间=短|中|长
  • 格式=1 | 5 | 6
  • 时间=今天|本周|本月(而不是默认值:所有时间)
通过这种方式,您可以使用查询组合来获得更多您感兴趣的结果


编辑:在搜索如何使用持续时间时,我遇到了堆栈溢出,这是指。例如,您可以使用这个实验性的“检索部分响应API”指定最大视图数(这可能有助于获取长尾),这只是您可以使用它进行的众多操作之一。

您使用和/或?我只是使用Youtube数据API来检索数据。我觉得AnalyticsAPI只是分析你自己的视频和频道(或其他用户的视频和频道),而不是一般的视频,不是吗?你能给出你使用的jar文件的链接吗?我试过gdata-youtube-1.0.jar(61.533字节)和gdata-youtube-2.0.jar(119.923字节),但是
VideoEntry
类没有
getTitle
方法?最新的V3API(google-API-services-youtube-V3-rev21-1.13.2-beta.jar-91.114字节)没有
VideoEntry
类?分析部分(顺便说一句,我之前的链接是错误的)用于检索YouTube分析报告,因此我认为这不是您想要的。我使用了本网站提供的gdata jar文件:我从这里获得了分页视频提要的代码:我希望这会有所帮助。谢谢你仔细考虑!我已经用
VideoEntry
类解决了我的问题:它从
BaseEntry
类继承了
getTitle
方法,该类位于gdata-core-1.0.jar中。在我的项目中添加了更多JAR之后,上面的代码运行良好。我现在使用这些jar:activation.jar、gdata-base-1.0.jar、gdata-client-1.0.jar、gdata-client-meta-1.0.jar、gdata-core-1.0.jar、gdata-media-1.0.jar、gdata-youtube-meta-2.0.jar、guava-r07.jar和mail.jar。感谢您的帮助。自定义查询参数确实可以帮助我学习一些东西!是的,我遇到了部分反馈反应。问题是它似乎只过滤原始请求的提要。例如,当我搜索关键字“sports”时,我通常会得到1000个结果,现在我使用部分反馈响应方法只显示我,例如,所有<500.000次的视频,它只显示2个条目(作为示例)。它似乎并没有创建一个全新的提要,而只是过滤原始请求。如果有别的方法我可能还没想过,请让我知道。如果它能够创建一个全新的响应提要,我的问题就会得到解决。
public static void printVideoEntry(VideoEntry videoEntry, boolean detailed) {
      System.out.println("Title: " + videoEntry.getTitle().getPlainText());

      if(videoEntry.isDraft()) {
        System.out.println("Video is not live");
        YtPublicationState pubState = videoEntry.getPublicationState();
        if(pubState.getState() == YtPublicationState.State.PROCESSING) {
          System.out.println("Video is still being processed.");
        }
        else if(pubState.getState() == YtPublicationState.State.REJECTED) {
          System.out.print("Video has been rejected because: ");
          System.out.println(pubState.getDescription());
          System.out.print("For help visit: ");
          System.out.println(pubState.getHelpUrl());
        }
        else if(pubState.getState() == YtPublicationState.State.FAILED) {
          System.out.print("Video failed uploading because: ");
          System.out.println(pubState.getDescription());
          System.out.print("For help visit: ");
          System.out.println(pubState.getHelpUrl());
        }
      }

      if(videoEntry.getEditLink() != null) {
        System.out.println("Video is editable by current user.");
      }

      if(detailed) {



        YtStatistics stats = videoEntry.getStatistics();
        if(stats != null ) {
          System.out.println("View count: " + stats.getViewCount());
        }
        System.out.println();


      }
    }

  public static void printVideoFeed(VideoFeed videoFeed, boolean detailed) {
      for(VideoEntry videoEntry : videoFeed.getEntries() ) {
        printVideoEntry(videoEntry, detailed);
      }
    } 

  public static void printEntireVideoFeed(YouTubeService service, 
          VideoFeed videoFeed, boolean detailed) throws MalformedURLException, 
          IOException, ServiceException {
         do {
           printVideoFeed(videoFeed, detailed);
           if(videoFeed.getNextLink() != null) {
             videoFeed = service.getFeed(new URL(videoFeed.getNextLink().getHref()), 
               VideoFeed.class);
           }
           else {
             videoFeed = null;
           }
         }
         while(videoFeed != null);
        }


  public static void main(String[] args) {

  try {

      YouTubeService service = new YouTubeService("test");

      YouTubeQuery query = 
              new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos"));
            query.setFullTextQuery("Sports");
            VideoFeed videoFeed = service.query(query, VideoFeed.class);
            printEntireVideoFeed(service, videoFeed, false);
  }
  catch(AuthenticationException e) {
    e.printStackTrace();
  }
  catch(MalformedURLException e) {
    e.printStackTrace();
  }
  catch(ServiceException e) {
    e.printStackTrace();
  }
  catch(IOException e) {
    e.printStackTrace();
  }
}