W
W
weranda2019-04-05 14:49:16
YouTube
weranda, 2019-04-05 14:49:16

Why is the YouTube API returning results but no video?

Greetings
There is a video ID: AvWYF1sa1Fw . There is no video, but when requesting data about it through the API in JSON format, it returns a value about the existence of some result of the existence of the video - in totalResults and resultsPerPage it returns ones instead of zeros.
5ca73768183bf293534355.png
In theory, these fields should be zeros. Please tell me why this is happening and maybe there is another way to check the existence of the video through the API?
I ask, like, standardly:

https://www.googleapis.com/youtube/v3/videos?id={VIDEO_ID}&part=snippet,contentDetails,statistics,status&key={API_KEY}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Satico, 2019-04-09
@Satico

My modest experience shows that when working through an API key, you can only indirectly check the existence of a video - if you have error handling configured when trying to request data from an empty array, as in the example with your video (ID AvWYF1sa1Fw).
Maybe, if you use Google OAuth 2.0, then the API will correctly process the request and return a response that is relevant in such cases, as it is written in the documentation for the Video resource:

notFound (404)
videoNotFound
The video that you are trying to retrieve cannot be found. Check the value of the request's id parameter to ensure that it is correct.

But I never received such an answer, so I use the get_headers() function . And only when I receive a 200 response (the video exists and is available), I make a call to the API. Your video gives a 404 error.
If you can't write a construct to check the HTTP header yourself, I can share a piece of code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question