问题
As it seems to me, YouTube API forbids to download video captions if you're not it's owner:
Captions for a video can only be created, retrieved, modified and deleted by the owner of that video.
The link above leads to documentation of YouTube API v2.0, which is deprecated, but it seems that in v3.0 this policy remains the same. If you try to download captions of a video, you'll get the following 403-error:
The permissions associated with the request are not sufficient to download the caption track. The request might not be properly authorized, or the video order might not have enabled third-party contributions for this caption.
At the same time you need only API_KEY to list captions of any YouTube video without any authorization (instantiating YouTube object as in this official example):
youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY,
new HttpRequestInitializer() {
public void initialize(HttpRequest request)
throws IOException {
}
}).setApplicationName("youtube-cmdline-search-sample").build();
CaptionListResponse captionListResponse = youtube
.captions()
.list("snippet", "jNhtbmXzIaM")
.setKey(API_KEY)
.execute();
List<Caption> captions = captionListResponse.getItems();
CaptionSnippet snippet;
for (Caption caption : captions) {
snippet = caption.getSnippet();
System.out.println("ID: " + caption.getId());
System.out.println("Name: " + snippet.getName());
System.out.println("Language: " + snippet.getLanguage());
System.out.println();
}
So does YouTube API v3.0 really restrict read access to captions while it's public data and there are even services and scripts allowing you to download captions of any YouTube video? How captions of any youtube video can be fetched (solutions via using API preferred)?
来源:https://stackoverflow.com/questions/32033153/does-youtube-api-forbid-to-download-video-captions-if-you-are-not-its-owner