Searching two channels from youtube - youtube

I am trying to search for "Food+Show" from two youtube channels. ABCNetwork and FoxBroadcasting. The query I gave is
http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=Food+Show&max-results=3&authors=ABCNetwork,FoxBroadcasting&prettyprint=true
The first result I got was id UKfLsIgJB1g where uploader is wafelsanddinges and not ABC or Fox. Please tell me why my query is not retuning correct result.

The parameter for the v2 data API is "author," not "authors." Unfortunately, fixing that won't solve the problem, as the retrieval of videos from a particular channel can only accept one author at a time. This is also true for v3 of the API.
The reason behind this is that the comma is treated as a concatenator, looking for a video that was published on FoxBroadcasting AND ABCNetwork (the use case for having multiple authors in that parameter is if you are retrieving activity feeds, in which case you want both feeds so having the comma serve as an AND is correct).
So for now, the only solution is two separate calls.

Related

YouTube API V3 - How to get ALL game live streams

I'm trying to get "ALL" game live streams from youtube using API.
The way I first used is through "Search.list" with parameters: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&eventType=live&maxResults=50&type=video&videoCategoryId=20. But in this way when I try to iterate results using PageToken, I can only get around 100 results while in the API response I can see "totalResults" is around 2000. Then I came into this topic and realized that "Search.list" is actually kind of "ranking" algorithm instead of "fetch all data from DB", which means "totalResults" is just an estimated number of results.
Then I came to use "liveBroadcasts.list" but it returns no results: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.liveBroadcasts.list?part=id&broadcastStatus=active&maxResults=50&_h=8&
And for other APIs, they either need channelId or other ids.
Is there any way to get all game live streams regardless of any ids?
According to Youtube Category ID list, Gaming resides on number 20 category. In case you want to try a different category in the future, instead of videoCategoryId=20, you can try videoCategoryId=31 - that's for Anime/Animation.
Try to run this on your browser to get all live streams:
https://www.googleapis.com/youtube/v3/search?part=snippet&eventType=live&type=video&videoCategoryId=20&regionCode=US&maxResults=50&key=SERVER_API_KEY_HERE

Youtube data API, query within channel lead to unexcpected results

I'm trying to use Youtube Data API for a project, the goal is seeking for a keyword in a channel and show the response to the user. I used the Search for "snippet" part and launched it querying for a specific keyword and specifing the channel id but the response didn't include all the videos that I was expecting. For instance, let's say that the channel has 10 videos with "c" charachter in the title, setting the q field with "c" value will return only one video.
On the other side, if I search for a whole word it returns some videos with that word on title and some other videos that doesn't have it, neither in description. The order criteria in this case seems to be ok (from the strongest match to the most weak), but I don't know if all of this is working fine.
Is this a normal behaviour or am I doing something wrong?
Setting an order on the search, the issue seems to be solved.

Can I search for channels which contain at least one video?

I am searching for channels against the YouTube API v3:
/search?part=id&type=channel&q=searchquery
Problem: It also returns channels which contain zero (0) videos.
I can see two possible approaches:
Use the &order=videoCount parameter, which sorts DESC the returned channels by the number of videos they contain.
Run a second query to search for videos in each channel, limit &maxResults=1 the returned amount of videos to one, and parse the result.
I don't want to take approach 1, as it changes the default &order=relevance, which I believe is fine-tuned by YouTube to return the most relevant channels first [still, the result may contain channels without videos, which makes YouTube's algorithm for calculating relevance questionable].
Approach 2 causes a lot of additional load, so it also isn't something that I'd want to do.
Is there a way to solve this in an elegant way that I don't see right now?
Approach 2 makes sense and assuming you'll use paging, you can run the second query as you need, instead of trying to run the query against the whole result set. That should be fine.

Accessing an item beyond start_index=1000 in a YouTube user upload feed

I am currently trying to pull data about videos from a YouTube user upload feed. This feed contains all of the videos uploaded by a certain user, and is accessed from the API by a request to:
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads
Where USERNAME is the name of the YouTube user who owns the feed.
However, I have encountered problems when trying to access feeds which are longer than 1000 videos. Since each request to the API can return 50 items, I am iterating through the feed using max_length and start_index as follows:
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?start-index=1&max-results=50&orderby=published
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?start-index=51&max-results=50&orderby=published
And so on, incrementing start_index by 50 on each call. This works perfectly up until:
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?start-index=1001&max-results=50&orderby=published
At which point I receive a 400 error informing me that 'You cannot request beyond item 1000.' This confused me as I assumed that the query would have only returned 50 videos: 1001-1051 in the order of most recently published. Having looked through the documentation, I discovered this:
Limits on result counts and accessible results
...
For any given query, you will not be able to retrieve more than 1,000
results even if there are more than that. The API will return an error
if you try to retrieve greater than 1,000 results. Thus, the API will
return an error if you set the start-index query parameter to a value
of 1001 or greater. It will also return an error if the sum of the
start-index and max-results parameters is greater than 1,001.
For example, if you set the start-index parameter value to 1000, then
you must set the max-results parameter value to 1, and if you set the
start-index parameter value to 980, then you must set the max-results
parameter value to 21 or less.
I am at a loss about how to access a generic user's 1001st last uploaded video and beyond in a consistent fashion, since they cannot be indexed using only max-results and start-index. Does anyone have any useful suggestions for how to avoid this problem? I hope that I've outlined the difficulty clearly!
Getting all the videos for a given account is supported, but you need to make sure that your request for the uploads feed is going against the backend database and not the search index. Because you're including orderby=published in your request URL, you're going against the search index. Search index feeds are limited to 1000 entries.
Get rid of the orderby=published and you'll get the data you're looking for. The default ordering of the uploads feed is reverse-chronological anyway.
This is a particularly easy mistake to make, and we have a blog post up explaining it in more detail:
http://apiblog.youtube.com/2012/03/keeping-things-fresh.html
The nice thing is that this is something that will no longer be a problem in version 3 of the API.

Retrieve most retweeted tweets for a given hashtag

I'd like to retrieve the tweets for given a hashtag and sort them from the most retweeted to the less retweeted.
The closest thing I've found is using the search call and use the type tag:
E.g.: http://search.twitter.com/search.json?q=TheHashTagHere&result_type=popular
However, I'm not sure on how "popular" option works.
For instance, if it finds 100 tweets with that hashtag I believe it should show the X most retweeted tweets, and if none of those tweets have been retweeted then it should show X of them randomly (or sorted in some other way like the most recent).
Unfortunately, if follows some kind of unknown rule to identify what's popular and what not and even hashtags with thousands of tweets might return only one or two results.
I hope I made myself clear. Thanks in advance :)
PS: I'll use PHP but I think that shouldn't affect the question?
Results will sometimes contain a
result_type field into the metadata
with a value of either "recent" or
"popular". Popular results are derived
by an algorithm that Twitter computes,
and up to 3 will appear in the default
mixed mode that the Search API
operates under. Popular results
include another node in the metadata
called recent_retweets. This field
indicates how many retweets the Tweet
has had.
Source (Emphasis are mine)
Just call with result_type=popular and check the recent_retweets node to see how popular it is. result_type=popular will become the default in an upcome release so beware if you omit this parameter.
Results with popular tweets aren't ordered chronologically. *
If you would like to always have results to show, use result_type=mixed: they will have the result_type in the "metadata" section with a value of "recent", and popular results will have "popular". A small reference about result_types:
mixed: Include both popular and real time results in the response.
recent: return only the most recent results in the response
popular: return only the most popular results in the response.
If a search query has any popular results, those will be returned at the top, even if they are older than the other results. *
*[Twitter API Announcements]
This isn't a programmatic method but rather works in the browser with a chrome extension (HackyBird) :
Install the extension
Search for a phrase e.g. #Social (twitter.com/search?q=%23Social)
Click the extension to sort it (you can adjust the ratio of retweets/likes used for sorting in extension options).
P.S. It'll also sort your or any other user's timeline.

Resources