14

When I call the captions.download endpoint with an ID that we retrieve from the captions.list endpoint, it always returns a 403. For example:

https://www.youtube.com/watch?v=1HRwpwOj4aA

I call captions.list with:

GET https://www.googleapis.com/youtube/v3/captions?part=id&videoId=1HRwpwOj4aA&key={YOUR_API_KEY}

This is response:

cache-control:  private, max-age=0, must-revalidate, no-transform
content-encoding:  gzip
content-length:  236
content-type:  application/json; charset=UTF-8
date:  Sat, 23 May 2015 17:55:57 GMT
etag:  "dhbhlDw5j8dK10GxeV_UG6RSReM/Rztb3ln4Zb6O07vb7_KSZi2y1NM"
expires:  Sat, 23 May 2015 17:55:57 GMT
server:  GSE
vary:  Origin, X-Origin

{
 "kind": "youtube#captionListResponse",
 "etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/Rztb3ln4Zb6O07vb7_KSZi2y1NM\"",
 "items": [
  {
   "kind": "youtube#caption",
   "etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/pwH-4wtyQJz0U3l57fA8uKm4e1I\"",
   "id": "kHlUsiuNS4TjB25loauZNXGrjK91I1tEdNyOpTRNA78="
  }
 ]
}

When I use the above id to call captions.download:

GET https://www.googleapis.com/youtube/v3/captions/kHlUsiuNS4TjB25loauZNXGrjK91I1tEdNyOpTRNA78%3D?key={YOUR_API_KEY}

This is response:

403 Forbidden
cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  29
content-type:  text/html; charset=UTF-8
date:  Sat, 23 May 2015 17:59:05 GMT
expires:  Sat, 23 May 2015 17:59:05 GMT
server:  GSE
vary:  Origin, X-Origin

Forbidden

Any ideas what could be happening here?

Lars
  • 141
  • 1
  • 3

4 Answers4

4

From the YouTube API docs:

403 Forbidden: 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.

theduck
  • 2,589
  • 13
  • 17
  • 23
  • 13
    Got some feedback from the YouTube team, apparently the captions.download endpoint only works for videos your google account owns. It is not usable for other videos. – Lars Jun 05 '15 at 22:15
  • 8
    can get captions, if the owner of the video enables third party contribution for the caption. Eg:- Try with this id: TqXDnlamg84o4bX0q2oaHz4nfWZdyiZMOrcuWsSLyPc= – Abhishek Ramachandran Oct 20 '16 at 05:09
  • You can no longer enable 3rd party caption contributions https://support.google.com/youtube/answer/6052538?hl=en. And without them you get a 403 "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." – rectalogic Feb 27 '21 at 13:49
  • So why do sites like `downsub` still work and download subtitles of any youtube video? – Nam Lee Sep 27 '22 at 17:05
  • @NamLee I asked this: https://qr.ae/pyWutU – AlwaysLearning Jul 16 '23 at 10:12
2

Instead caption download API that sometimes returns 403 (if video not have enabled third-party contributions for this caption) you can use youtube.com/api/timedtext

alexfv
  • 1,826
  • 2
  • 19
  • 22
0

what you wrote above about "only works for videos your google account owns" is not my experience. I just successfully ran captions.download on a video (about dog training) which I definitely do not own - do not even have a dog. However, I have tested the exact same code on the video mentioned here on stackoverflow and get a 403 error.

So no it doesn't always return a 403 sometimes it returns a 200! Try it with the dog video mentioned above:

python captions.py --videoid="jBN2_YuTclU" --action="download" --captionid='8S2GjnNfitU5HHoLyTeLxq_W1dP29YRFC8E8vFBUtws='

with the code you probably already have here.

It will need your client_secrets.json downloaded from the Google credentials page somewhere and a missing file youtube-v3-api-captions.json which you can get from here. The code launches a browser where you log in for OAuth2 authorisation.

Still, there must be a reason why it works for some videos and not others. @Abhishek might have it above. The wrong comment has been upvoted there. Nothing in the output of captions.list for a video that allows captions downloads and a video that does not is obviously different which would explains why one works and the other does not. If anyone can supply which {'key':'value'} pair in the youtube api controls this would be helpful.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
cardamom
  • 6,873
  • 11
  • 48
  • 102
-3

Status 403 Forbidden means that nobody has the right to access that URL. You shouldn't receive that message if you have the wrong API key, for example; that should give Status 401 Unauthorised. I'd check the URL carefully.

gnasher729
  • 51,477
  • 5
  • 75
  • 98