Whay are these same Youtube API REST urls returning different results? - youtube-api

My code uses this URL https://www.googleapis.com/youtube/v3/channels?part=id&snippet&id=UC9ctsJZ2aD1nCexfqj342NQ&key=[API_KEY]
which returns
{
"kind": "youtube#channelListResponse",
"etag": "69nKH4yrkGqjpjRH2T_M86dyIUI",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "A0IqlEsff608TjGHRdSAoqyeaiw",
"id": "UC9ctsJZ2aD1nCexfqj342NQ"
}
]
}
The sample code at https://developers.google.com/youtube/v3/docs/channels/list
has this call
curl \
'https://youtube.googleapis.com/youtube/v3/channels?part=id%2C%20snippet&id=UC9ctsJZ2aD1nCexfqj342NQ&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
And it returns the data I'm expecting:
{
"kind": "youtube#channelListResponse",
"etag": "oMV3kRZIiTu9TJSfDOaPpFGwsV0",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "-XETGcPmF-U5W8ONzQEJ9R8w-OI",
"id": "UC9ctsJZ2aD1nCexfqj342NQ",
"snippet": {
"title": "Better Bachelor",
"description": "Better Bachelor is a channel for open minded men (and women if so inclined) to talk about current events, news, opinions, humor and ways to better yourself and find happiness and understanding in today's society. This is an open forum where comments, talking points, concerns and discussion about topics are encouraged. Most content is focused towards single men's issues but may be applicable to others. I focus on viewing many issues from multiple or under represented angles.",
"customUrl": "#betterbachelor",
"publishedAt": "2019-02-08T10:23:44Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu9WcURyY8M4f-RKmm8LrlneJjRxEcPeKhfefPeXXA=s88-c-k-c0x00ffffff-no-rj",
"width": 88,
"height": 88
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu9WcURyY8M4f-RKmm8LrlneJjRxEcPeKhfefPeXXA=s240-c-k-c0x00ffffff-no-rj",
"width": 240,
"height": 240
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu9WcURyY8M4f-RKmm8LrlneJjRxEcPeKhfefPeXXA=s800-c-k-c0x00ffffff-no-rj",
"width": 800,
"height": 800
}
},
"localized": {
"title": "Better Bachelor",
"description": "Better Bachelor is a channel for open minded men (and women if so inclined) to talk about current events, news, opinions, humor and ways to better yourself and find happiness and understanding in today's society. This is an open forum where comments, talking points, concerns and discussion about topics are encouraged. Most content is focused towards single men's issues but may be applicable to others. I focus on viewing many issues from multiple or under represented angles."
},
"country": "US"
}
}
]
}
I can't see why snippet is being left out of the response for my API call.

Your URL is slightly incorrect.
Your code says &part=id&snippet& but the YouTube example says &part=id, snippet& (with ", " escaped to %2C%20).

Related

How to access a video's recordingDetails (esp location) from YouTube Data API v3

Can successfully search API for list of videos within a certain radius of a latlong, but how do I access the latlong from the response data?
I've used both YouTube's API playground tool and Postman as well as run some sample code in VSCode. Here is what 1 entry in the response list of "items" looks like. Also, where's the URL to the video?
{
"kind": "youtube#searchResult",
"etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/fsqRXEIJN16lp5xdhifY88TcbVg\"",
"id": {
"kind": "youtube#video",
"videoId": "5QPeyrHwlwk"
},
"snippet": {
"publishedAt": "2019-10-27T12:24:13.000Z",
"channelId": "UCT350j4u6alUKyF9eu2bGug",
"title": "Kincade Fire, PG&E Power Shutoffs, Extreme winds across California | Live overnight coverage",
"description": "Kincade Fire, PG&E Power Shutoffs, Extreme winds across California | Live overnight coverage 900000+ customers lose power due to PG&E public safety ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/5QPeyrHwlwk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/5QPeyrHwlwk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/5QPeyrHwlwk/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "ABC10",
"liveBroadcastContent": "none"
}
}
I would expect the response data to actually have the latitude and longitude, since I entered it into my query, but where is it? I've heard there's a property called 'recordingDetails' but how the heck do I get at it? I'm assuming this is just showing me the 'snippet' part, but is there another part I can query?

Is possible somehow explore youtube videos by hashtag?

I have been looking at the YouTube API and I am wondering if it is possible somehow search YouTube videos by hashtags e.g.
I want explore YouTube video for hashtag #funny
I have read YouTube API documentation but I haven't found anything.
Search: list
Returns a collection of search results that match the query parameters specified in the API request. By default, a search result set identifies matching video, channel, and playlist resources, but you can also configure queries to only retrieve a specific type of resource.
In my experience this is a full text search on title and description of the video so assuming your hash tags are in the description you should be able to search on them.
Request
GET https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&q=%23funny&key={YOUR_API_KEY}
Response
{
"kind": "youtube#searchListResponse",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/wR5yPzOxAnu-87xJGtSkLXz_78Q\"",
"nextPageToken": "CBkQAA",
"regionCode": "DK",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 25
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/IByts9zZTVNkc5EfbIDTKpE6pf8\"",
"id": {
"kind": "youtube#video",
"videoId": "DODLEX4zzLQ"
},
"snippet": {
"publishedAt": "2017-06-17T10:03:47.000Z",
"channelId": "UCKy3MG7_If9KlVuvw3rPMfw",
"title": "WATCH and TRY TO STOP LAUGHING - Super FUNNY VIDEOS compilation",
"description": "Can you hold your laugh while watching these clips? :) Mix of best and funniest animal & human fails. We bet you will lose this laugh challenge. Anyways, what is your favorite clip? :) Hope...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/DODLEX4zzLQ/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/DODLEX4zzLQ/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/DODLEX4zzLQ/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Tiger Productions",
"liveBroadcastContent": "none"
}
},
This is the video it returned WATCH and TRY TO STOP LAUGHING - Super FUNNY VIDEOS compilation #funny is in the description.
You can try it yourself here Google Apis Explorer

Certain videos not showing up in the api results

I have noticed that all videos from the account, Kanye West - Topic, don't show up in the api results. Does anyone have a reason why or a solution to fix this? For example, when I use the api search GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCRY5dYsbIN5TylSbd7gVnZg&type=video&key={YOUR_API_KEY}, it says there are 961 total results but the items section is empty.
Your GET request is correct but it's missing additional field resources parameters, so it doesn't know what you want to retrieve. I've added the fields to your GET REQUEST using the Google API Explorer and here's what it looks like:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCRY5dYsbIN5TylSbd7gVnZg&maxResults=50&q=%22Kanye+West%22&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CprevPageToken%2CregionCode%2CtokenPagination%2CvisitorId&key={API_KEY_HERE}
And the response was:
{
"kind": "youtube#searchListResponse",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/6VdmXA4FhXjg08y58iRnmXZY7wQ\"",
"nextPageToken": "CDIQAA",
"regionCode": "PH",
"pageInfo": {
"totalResults": 841,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/VSzDMW_CqJw-OMjo_vzPR2P40eI\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCRY5dYsbIN5TylSbd7gVnZg"
},
"snippet": {
"publishedAt": "2013-07-02T20:09:18.000Z",
"channelId": "UCRY5dYsbIN5TylSbd7gVnZg",
"title": "Kanye West - Topic",
"description": "Kanye Omari West is an American rapper, songwriter, record producer, fashion designer, and entrepreneur. Born in Atlanta and raised in Chicago, West first ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/hq1.jpg"
}
},
"channelTitle": "Kanye West - Topic",
"liveBroadcastContent": "none"
}
.. (long list below)
If you want to conduct additonal test, use the Youtube API Explorer.

Searching Channel with Youtube API

I am using Youtube Data Api V3 in my iOS App. Can some body give me some example for search thing the some Channel by name.
I am trying in the following way but its not working
https://www.googleapis.com/youtube/v3/search/list?key={YOUR_API_KEY}&part=snippet&type=channel&q=AnimalPlanetTV
Can anybody help me how i can get the channel data by name
Thanks
For Searching AnyYoutube Channel
https://youtube.googleapis.com/youtube/v3/channels?part=snippet&q=yoursearchquery&key=yourkey
This is a live example
You need to use Channel list of API V3
The result is like that with snippet
{
"kind": "youtube#channelListResponse",
"etag": "\"gMjDJfS6nsym0T-NKCXALC_u_rM/RKAMAh1QnoE3ilYYcvWIqvcDEZo\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"gMjDJfS6nsym0T-NKCXALC_u_rM/MenmiFqQVVN5JQ9MJpC9gddZ4Lw\"",
"id": "UCkEBDbzLyH-LbB2FgMoSMaQ",
"snippet": {
"title": "Animal Planet",
"description": "Animal Planet is the world's only entertainment brand that immerses viewers in the full range of life in the animal kingdom with rich, deep content via multiple platforms and offers animal lovers and pet owners access to a centralized online, television and mobile community for immersive, engaging, high-quality entertainment, information and enrichment.",
"publishedAt": "2007-02-14T18:26:59.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-FEsYkupUb-A/AAAAAAAAAAI/AAAAAAAAAAA/6SiqnVvRZJY/s88-c-k-no/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-FEsYkupUb-A/AAAAAAAAAAI/AAAAAAAAAAA/6SiqnVvRZJY/s240-c-k-no/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-FEsYkupUb-A/AAAAAAAAAAI/AAAAAAAAAAA/6SiqnVvRZJY/s240-c-k-no/photo.jpg"
}
}
}
}
]
}

Youtube Data API v3 search query with Freebase topics id and date

I am trying to use the YouTube Data API to search video by using Freebase topics.
It works for a simple search with one topic but it doesn't work for a search with 2 parameters : a topic id and a "publishedAfter" date.
For example, to search for videos about Richard Branson (Freebase id = /m/0n839), the youtube data api site :
https://developers.google.com/youtube/v3/docs/search/list#try-it
with the parameters :
part : snippet
topicId : /m/0n839
show a result of 2165 videos
But when you try to search videos about id = /m/0n839 with
part : snippet
topicId : /m/0n839
publishedAfter : 2013-05-21T21:47:38Z
the response indicates 147 videos but only 3 videos are contained in the response.
In the response, you can see that the 3 video ids are J6PY5vxLU8Y, SCkFwpW3kiE, CBvDp0i8Iok.
{
"kind": "youtube#searchListResponse",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/_-rYO0M0nvpPO6QN7DPFGEYa9ho\"",
"pageInfo": {
"totalResults": 147,
"resultsPerPage": 5
},
"nextPageToken": "CAUQAA",
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/3nxQ-ejnv0qekcbyq09HD2RQt_w\"",
"id": {
"kind": "youtube#video",
"videoId": "J6PY5vxLU8Y"
},
"snippet": {
"publishedAt": "2013-05-22T09:58:34.000Z",
"channelId": "UCimPiDCqxvfqwVJltL4YzHg",
"title": "Bono, Richard Branson, and Olivia Wilde Joined Matt Damon's Strike!",
"description": "Support the strike: http://strikewithme.org/ Millions of celebrities have joined Matt Damon's \"Toilet Strike\" protesting the lack of access to safe water and...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/J6PY5vxLU8Y/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/J6PY5vxLU8Y/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/J6PY5vxLU8Y/hqdefault.jpg"
}
},
"channelTitle": "water"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/gNslTbFkShGLlUBcXgHw7q9tuJc\"",
"id": {
"kind": "youtube#video",
"videoId": "SCkFwpW3kiE"
},
"snippet": {
"publishedAt": "2013-05-23T16:27:31.000Z",
"channelId": "UCeF4WiRKOA4XzphWYzR9aVw",
"title": "Sir Richard Branson dresses as an air stewardess after losing bet",
"description": "(Reuters) - A man was arrested at the Cannes film festival on Friday after firing a starting pistol during a live TV broadcast on the palm-lined waterfront, ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/SCkFwpW3kiE/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/SCkFwpW3kiE/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/SCkFwpW3kiE/hqdefault.jpg"
}
},
"channelTitle": "TheDailyPolitics247"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/-_OEOHhzgCBTLr7x5UoDk2kHlJM\"",
"id": {
"kind": "youtube#video",
"videoId": "CBvDp0i8Iok"
},
"snippet": {
"publishedAt": "2013-05-25T22:38:00.000Z",
"channelId": "UC2j75rAKcfjBAhW7WmNY4Qg",
"title": "Virgin Galactic Spaceship Passes Big Test (Y)",
"description": "A spaceship bankrolled by British tycoon Sir Richard Branson made its first engine-powered flight Monday. The test flight moves Virgin Galactic toward its go...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/CBvDp0i8Iok/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/CBvDp0i8Iok/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/CBvDp0i8Iok/hqdefault.jpg"
}
},
"channelTitle": "NewActionNews"
}
}
]
}
If you search for the next videos with nextPageToken : "CAUQAA", the response contains the same video ids (J6PY5vxLU8Y, SCkFwpW3kiE, CBvDp0i8Iok):
{
"kind": "youtube#searchListResponse",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/xMtmG2pQsuo_TFF8AtaaPea-cNc\"",
"pageInfo": {
"totalResults": 144,
"resultsPerPage": 5
},
"nextPageToken": "CAoQAA",
"prevPageToken": "CAUQAQ",
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/3nxQ-ejnv0qekcbyq09HD2RQt_w\"",
"id": {
"kind": "youtube#video",
"videoId": "J6PY5vxLU8Y"
},
"snippet": {
"publishedAt": "2013-05-22T09:58:34.000Z",
"channelId": "UCimPiDCqxvfqwVJltL4YzHg",
"title": "Bono, Richard Branson, and Olivia Wilde Joined Matt Damon's Strike!",
"description": "Support the strike: http://strikewithme.org/ Millions of celebrities have joined Matt Damon's \"Toilet Strike\" protesting the lack of access to safe water and...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/J6PY5vxLU8Y/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/J6PY5vxLU8Y/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/J6PY5vxLU8Y/hqdefault.jpg"
}
},
"channelTitle": "water"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/cEIRgKqwt1aa9hcWMNtGTiCJImc\"",
"id": {
"kind": "youtube#video",
"videoId": "h7hJ3FDGWY8"
},
"snippet": {
"publishedAt": "2013-05-22T10:01:25.000Z",
"channelId": "UCqcE1T9zcUQyX3hHH4EM7sQ",
"title": "Sir Richard Branson in Dubai",
"description": "The man behind the Virgin brand stopped by Kris Fade's show last week - broadcasting from the Burj Khalifa, the world's tallest building.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/h7hJ3FDGWY8/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/h7hJ3FDGWY8/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/h7hJ3FDGWY8/hqdefault.jpg"
}
},
"channelTitle": "Kimberleyleonard"
}
}
]
}
Did I do something wrong ?
The "totalResults" attribute has, in previous versions of the API, always just been an estimated value that the search algorithms provide before actually retrieving any results, so it's likely safe to assume that is the case for v3 as well. However, it is a little odd that the estimate could be so far off; for your query, there really are just several results (5 or 6, I think ... as several have been uploaded since you made this initial post).
I've played around with various parameters for a bit, and it looks as though the factor which has the single-most influence as to the accuracy of the totalResults approximation is the 'q' parameter -- the more specific of a value you provide there, the more accurate the totalResults become.
Of course, in your query, then, the q parameter is empty, and the totalResults approximation is incredibly far off (in fact, if you change the publishedAfter parameter to be May 1st intead of May 21st, you actually get it approximating LESS total results, even though it's an earlier date!). If you do a query like this, however:
https://www.googleapis.com/youtube/v3/search?part=id&maxResults=50&publishedAfter=2010-05-01T21%3A47%3A38Z&topicId=%2Fm%2F0n839&key={YOUR_KEY}&q=Bran
Then you get a totalResults approximation that exactly matches the number of real results.
Of course this can be frustrating, because when incorporating Freebase IDs you often don't WANT to use the q parameter -- the whole point of freebase IDs is to use semantically relevant info that's based in more than just string matching! But it's clear that this is telling us something about the internal YouTube search algorithms and what they rely on. I'd venture that as Freebase integration becomes more mature, the search algorithms will be better able to adapt and you'll start seeing better totalResults approximations again.
As a workaround, you can use what you've noticed with the 'nextPageToken' to get a better count. In your query, set your maxResults to 50, and when you get actual results, have your routine count them. If they're less than 50, you've got them all. If it is 50 on that page, you might want to pre-fetch the next set of results (if they are new results, you're good to go, while if they are the same results as what you have, then you had exactly 50 responses). The one problem is that this will prevent you from displaying in your app an accurate count of total results (i.e. if you've got pagination going somewhere), so it's not perfect, but what workaround is?
I'm pretty sure the discrepancy between number of results and number actually shown is due to how date restrict ( start_time: 1369172858, the representation of "publishedAfter : 2013-05-21T21:47:38Z") is implemented.
By the way, I now see 10 matches, including the three mentioned.
First results are retrieved using the narrowist restrict range that includes the requested date range. That's how you can get ~140 matches. The videos that survive retrieval are then filtered, rejecting those outside the actual requested range. It's pretty plausible that 130 videos are dropped at that stage, leaving the 10 that actually satisfy the request.
The count of matches indicates number retrieved -- for date range, this will typically be an overestimate, possibly severe.
We generally don't warrant that the number reported as "matched" all actually match, since various kinds of filtering happen after retrieval.

Resources