YouTube Data API search not honoring publish after

2020-02-06 13:32发布

问题:

I have this query

    YouTube.Search.List search = youtube.search().list("id");
    search.setOrder("viewCount");
    search.setMaxResults(50);
    search.setPublishedAfter(new DateTime(publishedAfterDate));
    search.setPublishedBefore(new DateTime(new Date()));
    search.setType("video");
    search.setKey(getYoutubeKey());

Which was working perfectly fine up until a few months ago. Then, all of a sudden it seems that Google must have changed something in their data API and the "PublishedAfter" date is no longer being honored.

I checked in a debugger and the value of "publishedAfterDate" resolves just fine. My query for videos published after one week ago is now returning videos from a year ago. There are no errors or anything of that sort, the API just doesn't return the correct results when the same exact code was working perfectly fine a few months ago.

Any ideas?

Live demo

Full source

Another weird tidbit, on the live demo if you click "All Time", you'll notice that the data API is even returning the same videos more than once. This is very weird and also didn't used to happen a few months ago.

回答1:

This issue is related to the following ones:

  • Order doesn't work when using youtube API v3;
  • publishedAfter parameter appears to be broken now;
  • Youtube Data API v3: Sort by date not working

See also Google's issue #128673552, https://issuetracker.google.com/issues/128673552.