Thursday, April 26, 2012

Re: [YouTube-API] Re: strange search result

Hi Jeff, I invoke a search with the searchClicked function declaring showMyVideos as the callback function. We'vebeen using this technique for a while and it works robustly. It was only this morning that the search criteria I described caused the error. Its strange that an extra character in the search term can cause the error. I've tested many combinations of search terms to try to recreate so it must be rare but be good to get to the bottom of it.

My code is based on a code sample from youtube API from some time ago. Maybe I should be using a more up to date technique?

Cheers

Will



function searchClicked(e) { var q = $('#searchText').val(); //create a JavaScript element that returns our JSON data. var script = document.createElement('script'); script.setAttribute('id', 'jsonScript'); script.setAttribute('type', 'text/javascript'); script.setAttribute('src', 'http://gdata.youtube.com/feeds/' + 'videos?q='+q+'&start-index='+pageIndex+'&max-results=50&' + 'alt=json-in-script&callback=showMyVideos&' + 'orderby=relevance&sortorder=descending&format=5'); //attach script to current page - this will submit asynchronous //search request, and when the results come back callback //function showMyVideos(data) is called and the results passed to it $("body").append(script); } function showMyVideos(data) { var feed = data.feed; var entries = feed.entry || []; videoResults=[]; for (var i = 0; i < entries.length; i++) { var entry = entries[i]; var obj = new Object(); obj.ytID=ytID;
obj.playCount=entry.yt$statistics.viewCount.valueOf();
Uncaught TypeError: Cannot read property 'viewCount' of undefined
obj.thumb=entry.media$group.media$thumbnail[0].url;
obj.author=entry.author[0].name.$t;
obj.duration=entry.media$group.media$content[0].duration;
obj.description=replaceSpecialChars(entry.media$group.media$description.$t);
obj.title=replaceSpecialChars(entry.title.$t);
obj.ytLink=entry.link[0].href;
obj.cat = entry.category[1].label;
videoResults.push(obj);
}
//create instance of master view
directory = new VideoDirectoryView();
}
On 26 April 2012 21:10, Jeffrey Posnick <jeffy@google.com> wrote:
Hello,

 I can't reproduce what you're seeing. I also don't know what you mean
when you're talking about the viewCount property, as that's an
attribute associated with an individual video, not a search results
feed.

 Could you provide an example of the specific response values that are
causing problems?

Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev


On Apr 26, 12:34 pm, wg <reachw...@gmail.com> wrote:
> Looking deeper, there are results but the web app bombs out because it
> tries to read the viewCount property which is suddenly undefined when the
> search term is as described below. So to summarise what we found so far..
> Search 'david camero rupert' returns a viewCount property but 'david
> cameron rupert' returns viewCount of undefined. Would best practice to be
> to surround all references to properties in conditional 'if !undefined' ?
> surely not!?
>
>
>
>
>
>
>
> On Thursday, April 26, 2012 5:12:14 PM UTC+1, wg wrote:
>
> > This could be something to be ready for when our clients ask why some
> > search terms don't work. We've been looking at this again - it really is
> > making us very curious. The search term 'david cameron ruper' with no 't'
> > on rupert returns results of yes guess what - the recent news - but when
> > the result has a 't' added on the end no results are returned. Likewise,
> > when the search term is 'david camero rupert' with no 'n' on cameron we get
> > a couple of results but as soon as the name is completed no results. If
> > anybody else can be bothered to try let us know if you have the same
> > strange results in any other 3rd party youtube search situation. Perhaps
> > there are other terms that for some reason will return no results for
> > whatever reason. It would be good to know the reason as we might get
> > questions from our clients!
>
> > On Thursday, April 26, 2012 1:55:38 PM UTC+1, wg wrote:
>
> >> This is a weird observation I just stumbled across.. if I search for
> >> 'David Cameron' using the youtube search API I get results. If I
> >> search for 'Rupert Murdoch' I also get results. However, if I do a
> >> search for 'David Cameron Rupert Murdoch' it doesn't work. If I do a
> >> search for 'David Cameron Nick Clegg' or David Cameron and anybody
> >> else it does work. Why would a search associating Cameron and Murdoch
> >> not work in the youtube API? It works on youtube.com... weird! Can
> >> anybody think of a non conspiracy related technical reason?

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.


--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment