3

One of the successful load is like that:

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

However, when the video is private or doesn't exist, it returns just a message with an http error status code.

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

I create an example unique callback function name like "jsonp1335008664824" and append the url as src for a script tag and catch the function when the script loaded. However if it returns an error, youtube doesn't return the content as a callback function and I can't catch any of them. Because script tag doesn't have "onerror" attribute, I don't even know whether it's loading or returned an error like 404 or 503 status codes.

It seems the only whay to handle it is setting timeout function when I append script tag. However it's not a reliable way to do that so I'm looking for another option. I know that even I can catch the status code, I can't get error message but as I see, there's only two status code and two errors that are 404 for "Video not found" or 503 for "Video is private".

burak emre
  • 1,501
  • 4
  • 22
  • 46
  • This might be a duplicate of: http://stackoverflow.com/questions/538745/how-to-tell-if-a-script-tag-failed-to-load. It annoys me too, I will send this to the YouTube API team... – Jonny Burger Apr 21 '12 at 12:36
  • I saw that question but because it's more related to youtube api problem, I wanted to create a new question. And I also send this question to youtube api developer forum. (https://groups.google.com/forum/?fromgroups#!forum/youtube-api-gdata) – burak emre Apr 21 '12 at 12:40

1 Answers1

0

I got the answer from Youtube Developer Forum. As a result, jsonc is a better way to handle these kind of request. And this this development the requests became this layout: 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 POST and PUT request from now on.

burak emre
  • 1,501
  • 4
  • 22
  • 46