Error handling in youtube api data in javascript

One of the successful workloads is:

http://gdata.youtube.com/feeds/api/videos/N7m86aMNjlQ?callback=jsonp1335008664824&alt=json-in-script

However, when the video is private or does not exist, it only returns a message with the error status code http.

http://gdata.youtube.com/feeds/api/videos/zkZBEnBjOjY?callback=jsonp1335008664915&alt=json-in-script

I create an example of a unique callback function name like "jsonp1335008664824" and add url as src for the script tag and catch the function when the script loads. However, if it returns an error, youtube does not return the contents as a callback function, and I cannot catch them. Since the script tag does not have the "onerror" attribute, I donโ€™t even know if it loaded or returned an error, such as 404 or 503 status codes.

It seems the only one he can handle is setting the timeout function when I add the script tag. However, this is not a reliable way to do this, so I am looking for another option. I know that even I can catch the status code, I canโ€™t get an error message, but, as I see, there are only two status codes and two errors 404 for "Video not found" or 503 for "Video - personal".

+3
source share
1 answer

I got a response from Youtube Developer Forum. As a result, jsonc is the best way to handle such a request. And it was with this development that requests became such mockups: http://gdata.youtube.com/feeds/api/videos/zkZBEnBjOjY?callback=jsonp1335008664915&alt=jsonc&v=2

And also, as I learned from here , we can use XMLHTTPRequest in Youtube Data Api. This is awesome because we can make a POST and PUT request from now on.

0
source

All Articles