javascript - Youtube Data API v. 3 - Display channel author name of private / deleted video -


this 1 of them youtube internal decisions highly counter-productive. correct me if i'm wrong, don't want expose channel name of private / deleted videos. call 'bug' if happens ( http://code.google.com/p/gdata-issues/issues/detail?id=5893 ). happens if solely request video ids public beforehand later became private or deleted? get, via usage of youube data api v3, "response undefined" error message in console. happens when message happens? code breaks!

this code use:

function displaythemvideos(yeah) { var yeah = $("#thosemissingids").text(); var vidrequestoptions = { id: yeah, part: 'snippet', fields: 'items(id),items(snippet(channelid)),items(snippet(channeltitle)), items(snippet(title)),items(snippet(thumbnails(default)))' };  var vidrequest = gapi.client.youtube.videos.list(vidrequestoptions); vidrequest.execute(function(response) { var videoiditems = response.result.items; if (videoiditems) { // if results displayresults(videoiditems); } else { // if no results alert('sawwy, youlose, thx youtube!'); // alert never fires! } }); } 

now undefined "response" empty request sent app youtube server. youtube answers empty "item" tag doesn't displayresults(videoiditems) function gets fired without item display! should @ least let channel name , channel id filter through user click on link in order access remaining public videos of channel (wouldn't productive jeff p?).

so dilemma else section working so:

displayresults(videoiditems); } else { // if no results or if results return empty or response "undefined" alert('sorry pal these ids ___________ missing. click channel link access public videos of channel.'); } 

the else part works should similar api calls demonstrated in youtube data api v.3 sample code, guess isn't able handle empty requests.

so do? have use ajax call success fail error handling? said beforehand, api returns empty request response legit response content comes empty private/deleted videos, hence, "undefined" code breaking along wway.

any hints leading working solution help! thx guidance.

i can partly answer question. easiest use catch of try - catch method detects except syntax errors, helpful in detecting empty response (undefined) , activating function can access youtube player displaying current availability status of missing id:

...  var vidrequest = gapi.client.youtube.videos.list(vidrequestoptions); vidrequest.execute(function(response) {  try { var videoiditems = response.result.items; if (videoiditems) { // if results displayresults(videoiditems); return false; }  } catch (e) { // put code here handles errors such empty or undefined response // otherwise breaks code  } { // optionally, put code here trigger }  }); 

hope helps others.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -