I'm trying to use "Try It!" on this page:
https://developers.google.com/youtube/v3/docs/videos/update
But I get Bad request error. Where should I set ID of the video I want to update? And what is the request format for updating video title or description?
The request format is to send a "video resource" JSON packet, which looks something like this:
{
"id": "GS9h8M3ep-M",
"kind": "youtube#video",
"etag": "\"MhkxP1IuK4vYJ-nhM3d9E49-2oU/HUmayeWdVX19XyvhE5c2RnbZjgA\"",
"snippet": {
"publishedAt": "2012-11-10T09:36:49.000Z",
"channelId": "UC070UP0rK7rShCW1x4B4bgg",
"title": "Finding Ourselves: The Humanities as a Discipline",
"description": "Lecture delivered by Geoffrey Harpham, of the National Humanities Center, at the inaugural event of the Brigham Young University Humanities Center.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/GS9h8M3ep-M/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/GS9h8M3ep-M/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/GS9h8M3ep-M/hqdefault.jpg"
}
},
"categoryId": "27",
"tags": [
"humanities",
"Harpham",
"BYU"
]
}
}
When doing an update, you need only send the "id" and "kind" values, along with, in this case, a partial "snippet." Be aware, however, that for writeable attributes -- snippet.title, snippet.description, snippet.tags, snippet.categoryId, and status.privacyStatus -- omitting them will have them revert to the default ('public' for privacyStatus, blank for the other 4). If you were to omit the categoryId, then, it results in a bad request, because it would be as if you were setting it to be in no category, and Youtube doesn't allow a video to not have a category (this is, then, making categoryId a defacto required element). You also have to re-include the tags, the description, and the privacy status (unless you want it to default to public) so they won't be cleared out. Thus to modify the title, you'd include the snippet, its title, and its category ID, like this:
{
"id": "GS9h8M3ep-M",
"kind": "youtube#video",
"snippet": {
"title": "I'm being changed.",
"categoryId": "27",
"tags": [
"humanities",
"Harpham",
"BYU"
],
"description": " can be changed, too, but if I'm not to be I still have to be included as I was before. I will be emptied out if omitted."
}
}
Related
As you know, youtube has a property that there are subtitles of videos with soft-coded. By clicking cc it can be seen. There is also a website helping a guy to learn pronounciation of a english word, www.youglish.com
The website searches subtitled videos a given word and brings the part of it with the word said. That is, it is able to search videos by subtitle. What is the way/method/step(s) to do that? Besides, ibm has a work similar that
You can use search.list for request videos that:
has closed caption.
matches with the search terms.
In this example, this is the search.list request for search videos with closecaption enabled and that matches with the search term (charming):
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=4&q=charming&type=video&videoCaption=closedCaption&fields=items(id(channelId%2Ckind%2CvideoId)%2Ckind%2Csnippet(channelTitle%2Cdescription%2Ctitle))&key={YOUR_API_KEY}
Demo available in Google API Explorer:
These are the results:
{
"items": [
{
"kind": "youtube#searchResult",
"id": {
"kind": "youtube#video",
"videoId": "ztsbgEUzVpc"
},
"snippet": {
"title": "CHARMING Official Trailer (2018) Demi Lovato, Sia, Animation Movie HD",
"description": "CHARMING Official Trailer © 2018 - Smith Global Media Comedy, Kids, Family and Animated Film, Blockbuster, Action Cinema, Blockbuster, Scifi Movie or ...",
"channelTitle": "ONE Media"
}
},
{
"kind": "youtube#searchResult",
"id": {
"kind": "youtube#video",
"videoId": "sO5F8DulPPk"
},
"snippet": {
"title": "How to be more Charismatic - 6 Charisma Tips to be more Charming and Attractive",
"description": "Use my FREE 27 Confidence-Boosting Hacks: https://practicalpie.com/confidence/ Want my TOP 10 book list?: https://practicalpie.com/book-list/ Get a girl to like ...",
"channelTitle": "Practical Psychology"
}
},
{
"kind": "youtube#searchResult",
"id": {
"kind": "youtube#video",
"videoId": "gesBAZo2_l4"
},
"snippet": {
"title": "9 Tricks to Be the Most Charming Person in the Room",
"description": "How to be a bit more charming? Some people could easily gain the trust of everyone and create a positive image of themselves? Jeff Haden, one of the most ...",
"channelTitle": "BRIGHT SIDE"
}
},
{
"kind": "youtube#searchResult",
"id": {
"kind": "youtube#video",
"videoId": "wMVPU3uUc5g"
},
"snippet": {
"title": "10 Signs You Are An Exceptionally Charming Person",
"description": "If you have these signs you are an exceptionally charming person – even if you don't think you are! Charm is the power or quality of delighting, attracting or ...",
"channelTitle": "BRAINY DOSE"
}
}
]
}
Unfortunately, not all returned videos has (in is captions) the given word - in this case, the word: charming.
Hence, you have to loop the videos returned in the search.list response and select the one who has indeed the given word.
Next, you can get the captions by passing the videoId:
You can use this URL for get the captions:
https://video.google.com/timedtext?type=track&v=<VIDEO_ID>&id=0&lang=en
The working jsfiddle for retrieve the captions by modifying the URl and add the videoId is here.
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.
There seems to be an error when uploading a video to YouTube using the API when using the "Videoblogging" category which has an ID of 21. I even used the document to retrieve the ID at https://developers.google.com/youtube/v3/docs/videoCategories/list under the "Try it" section.
{
"kind": "youtube#videoCategory",
"etag": "\"0Fu6lI6VPLdRMlQU3wwNcowdAUs/EapFaGYG7K0StIXVf8aba249tdM\"",
"id": "21",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Videoblogging",
"assignable": false
}
With other categories such as Sports
{
"kind": "youtube#videoCategory",
"etag": "\"0Fu6lI6VPLdRMlQU3wwNcowdAUs/9GQMSRjrZdHeb1OEM1XVQ9zbGec\"",
"id": "17",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Sports",
"assignable": true
}
The only difference is Assignable, so are categories which aren't assignable won't work as the documentation around this area isn't clear.
VideoCategories
snippet.assignable
Indicates whether videos can be associated with the category.
Based on this document, it seems that assignable with a false value will return a “invalidCategoryId” error message for associating a video with this category.
Hope this helps
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"
}
}
}
}
]
}
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.