400 Bad Request while fetching videos of a particular youtube channel - youtube

I want to get list of videos of a particular YouTube channel.
I followed this SO answer https://stackoverflow.com/a/20795628/5383573
Every time I am getting
400 Bad Request
Suppose I want to get all the video of NDTV Channel.
Its YouTube url is https://www.youtube.com/user/ndtv/videos
I went to this URL https://developers.google.com/youtube/v3/docs/playlists/list
Fill the boxes as
Part: NDTV
Channel ID:ndtv
Max Result: 50
and click Execute
It gives me Request as
GET https://www.googleapis.com/youtube/v3/playlists?part=ndtv&channelId=ndtv&maxResults=50&key={YOUR_API_KEY}
And response
400 Bad Request
{
"error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unknownPart",
"message": "ndtv",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "ndtv"
}
}
How can I get all the videos in JSON response?
Sorry for my bad English.
Any help will be appreciated.Thanks in advance

Playlists: list has five valid parts
The list below contains the part names that you can include in the
parameter value and the quota cost for each part: contentDetails: 2
id: 0 player: 0 snippet: 2 status: 2
A your error message states ndtv is not valid part. NDTV is also not a valid channel id. A channel id looks like this UCtb0gXU-ht24V_fgeXGGjwA
The easest way tof ind the channel id is to check YouTube
https://www.youtube.com/channel/UCtb0gXU-ht24V_fgeXGGjwA

NDTV has 3 featured channels, those with channel_id
UCZFMm1mMw0F81Z37aaEzTUA,UC9CYT9gSNLevX5ey2_6CK0Q,UCf9StUUEcbRpbvpdKx5eS_g
The following GET requests will return json response.
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId={ndtv_channel_id}
replace ndtv_channel_id with the channel id.

Related

Youtube API: Get videos from autogenerated channels (like Music)

Is there any way to get the videos from autogenerated channels (like this one https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ/videos) directly, without having to access all the playlists?
Using https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&key=... gives me 0 items.
Gives me 0 Items
If you mean running the following exactly
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&key=
Returns the following error
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
That is because you have neglected to add an API key on the end.
Try testing in the query explorer this seams to return quite a few no idea if its all of them.
GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&maxResults=25&key={YOUR_API_KEY}
returns
"pageInfo": {
"totalResults": 786,
"resultsPerPage": 25
},
This apears to return a list of the playlists only for this user.
Update:
If you try and only request videos for this user you get 0 returned. This is not the case for any other user which i have tested.
GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&maxResults=50&order=date&type=video&key={YOUR_API_KEY}
This leads me to believe that it is not possible to retrieve the videos for an autogenerated channel. I recommend either logging this as a bug or adding it as a feature request here. Personally i think its more a feature request.

Getting status for playlist from Youtube API

I'm building an app that based on user's choice connects to youtube api and get's list of videos of certain playlist.
I would like to make it safe to use and if the status is not 200, make it impossible for the next screen to show.
The JSON result from my request does not return any information on the status other than privacy status (similarly, if I get data for a video not a playlist I get detailed information) :
var urlString = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=500&playlistId=\(playlistId)&key=XXXXX"
"status":{
"privacyStatus":"public"
}
How do I verify that the request for the playlist is valid?
Thanks!
I have not found a reliable way to test the YT api status, so I generally will look for results from the call that should be there. And if they are not there (i.e. empty or '0' ) , then it is normally a failed call.
So [totalResults] and/or [title] as example.
There are two parts here.
You need to determine if the actual HTTP request was successful or not (that is the request to https://googleapis/youtube/v3/[method]?[parameters])
You have a specific requirement where you need to handle cases where there is no data. The response from the API itself will not explicitly provide this to you, instead you need to define what failure means.
With this in mind, you could implement two levels of checks:
Check 1 - HTTP status code
The first level would check the HTTP status code (200 = OK, 400 = Bad Request, etc.).
If your API request returns a status of 200, you can move on to the next level of checks (see Check 2). However, if your API request returns a status of 400, then the request has failed and no further checks are required (or necessary).
Note: If you do get a 400 status, there is some JSON in the response which contains detailed information regarding the error.
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"message": "No filter selected. Expected one of: id, playlistId",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "No filter selected. Expected one of: id, playlistId"
}
}
Check 2 - Data
The second level would check to see if any results have been returned (as it seems possible to have a HTTP status code of 200 and no results).
This has nothing to do with the status of the actual HTTP request itself. Instead you have to check the response to see if the data you application requires is present or not.
With the example of a 200 response below, the items array is empty. So you could say that even though the request was successful, this is a failure condition and not show your next screen.
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"[etag would appear here]\"",
"nextPageToken": "CAAQAA",
"pageInfo": {
"totalResults": 199,
"resultsPerPage": 0
},
"items": [
]
}
Note: The above is an example where the results per page was purposely set to 0.

DELETEing a YouTube watchLater playlist item failing - returning 404

i have code that deletes an item from my youtube watchLater playlist. this was working ok up to about two weeks ago - now i'm getting a 404 error from youtube.
here's the sequence of requests and responses (with authentication details stripped, of course):
get playlist items request:
GET https://www.googleapis.com/youtube/v3/playlistItems?fields=items/id&part=snippet&playlistId=WLlue5EIJLscoxMgEkEZfq_A
get playlist items response:
{
"items": [
{
"id": "V0xsdWU1RUlKTHNjb3hNZ0VrRVpmcV9BLjU2QjQ0RjZEMTA1NTdDQzY="
}
]
}
delete request:
DELETE https://www.googleapis.com/youtube/v3/playlistItems?id=V0xsdWU1RUlKTHNjb3hNZ0VrRVpmcV9BLjU2QjQ0RjZEMTA1NTdDQzY=
delete response:
{
"error": {
"errors": [
{
"domain": "youtube.playlistItem",
"reason": "playlistItemNotFound",
"message": "Playlist item not found.",
"locationType": "parameter",
"location": "id"
}
],
"code": 404,
"message": "Playlist item not found."
}
}
when i view the playlist via the youtube web site, i can see that the item hasn't been deleted.
the docs for the api indicate that i'm doing everything correctly. while debugging i noticed that the playlist item id is a base64 encoded string; i get 404 using both the encoded and decoded string.
this issue isn't limited to one particular item; it appears any item i place in my watchLater playlist cannot be deleted. i don't have any issues deleting items from other playlists; only watchLater is having this problem.
anyone have any idea what's going on?
Edit (Oct 2016): Google have said the Watch Later playlist has been deprecated. See https://developers.google.com/youtube/v3/revision_history
The issue is closed in the google issue tracker:
Marking this issue as Obsolete as the Watch Later playlist has been deprecated. Please see the Revision History for details: https://developers.google.com/youtube/v3/revision_history
In addition, requests to retrieve playlist details (playlists.list) or playlist items (playlistItems.list) for a channel's watch history or watch later playlist now return empty lists. This behavior is true for the new values, HL and WL, as well as for any watch history or watch later playlist IDs that your API Client may have already stored.

trying to show more than 50 results corresponding to single topic id using freebase in android

I want to get more than 50 youtube video results corresponding to topic id ........so i am trying to get next page token.......
in youtube api v3 in android
and url used is....
https://www.googleapis.com/youtube/v3/videos?part=id,snippet&order=relevancee&topicId="+topicId+"&q="+videoId+"&key="
but the error giving is......
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"message": "No filter selected.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "No filter selected."
}
}
You should set type = video
Whenever you are using a video specific filter you have to filter type as well. As search is unified, otherwise it normally returns playlist, channel and videos as a result.
You can always try your queries in API explorer before implementing.

Searching for HD videos using the YouTube API v3?

I am getting invalid combination of search filter error while retrieving the HD videos. this was the url - https://www.googleapis.com/youtube/v3/search?part=snippet&q=drama&videoDefinition=high&key={Developerkey}
Error report
{
"error": {
"errors": [
{
"domain": "youtube.search",
"reason": "invalidSearchFilter",
"message": "Invalid combination of search filters and/or restrictions.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "Invalid combination of search filters and/or restrictions."
}
}
Is it possible to retrieve HD videos? Please guide me. How can I get a response from this URL? Thanks
You also need to include the type=video query parameter, since filtering on high definition only makes sense when the results are limited to videos.
That being said, the error message that's returned isn't actually helpful, and I'll ask the engineering team to revise it so that it clarifies what's wrong.

Resources