In YouTube's Data API, data are returned in fields, and fields are grouped in parts. In the YouTube documentation, YouTube Data API Overview, the section, How to use the part parameter, gives a list of the parts available for videos:
snippet, contentDetails, fileDetails, player, processingDetails, recordingDetails, statistics, status, suggestions, topicDetails
There are two things I have not found in the documentation:
The list of parts available for channels and playlists.
The list of fields available in each part for videos, channels, and playlists.
Where can I get that information?
Also, some fields are available to the public, while others are only available to the owner of the subject resource. So in the list of fields, I need to know which I can query and which are restricted.
Found the answer:
Channels
Parts: docs/channels/list#parameters
Fields: docs/channels#properties
Restrictions: docs/channels/list#auth
Playlists
Parts: docs/playlists/list#parameters
Fields: docs/playlists#properties
Restrictions: If there are any, they don't seem to be documented.
Playlist items
Parts: docs/playlistItems/list#parameters
Fields: docs/playlistItems#properties
Restrictions: If there are any, they don't seem to be documented.
Videos
Parts: docs/videos/list#parameters (The list at that link gives three additional parts that are not in the list at How to use the part parameter: id, liveStreamingDetails, and localizations.)
Fields: docs/videos#properties
Restrictions: Stated in the descriptions of the fileDetails, processingDetails, and suggestions fields.
===================================
Fields that are missing from my previous answer are
contentDetails
regionRestriction
hasCustomThumbnail
status
failureReason
rejectionReason
publishAt (But this should never appear in a public listing because it only applies to videos with privacyStatus = 'private`.)
selfDeclaredMadeForKids (But only returned if authorized.)
statistics
dislikeCount (But only returned if authorized.)
player
embedHeight
embedWidth
recordingDetails
location
recordingDate
liveStreamingDetails
6 fields
localizations
key (language)
I have used a method to get a partial list of the public fields available for videos. This is a hack and I hope someone will post a better answer, preferably a link to the answer in official YouTube documentation.
Until we get that answer, here is the hack I used:
First, I took the list of the ten parts given for videos and submitted it in an API call for three arbitrary videos:
https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,fileDetails,player,processingDetails,recordingDetails,statistics,status,suggestions,topicDetails&id=XqZsoesa55w,kJQP7kiw5Fk,F4tHL8reNCs&key=<key>
The result was this error message:
The request is not properly authorized to access video file or
processing information. Note that the fileDetails,
processingDetails, and suggestions parts are
only available to that video's owner.
That is information. It tells me that those three parts are not publicly available, so I can't query them on videos I don't own.
So next I submitted the same request with those three parts removed:
https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,player,recordingDetails,statistics,status,topicDetails&id=XqZsoesa55w,kJQP7kiw5Fk,F4tHL8reNCs&key=<key>
I then took the response from that and parsed the JSON to extract the labels at the third and fourth level of nesting. These are mostly the part and field names. The first three rows of the following table are fields; the rest are parts with their constituent fields.
Field or part
Field
kind
etag
id
snippet
publishedAt
channelId
title
description
thumbnails
channelTitle
tags
categoryId
liveBroadcastContent
defaultLanguage
localized
defaultAudioLanguage
contentDetails
duration
dimension
definition
caption
licensedContent
contentRating
projection
status
uploadStatus
privacyStatus
license
embeddable
publicStatsViewable
madeForKids
statistics
viewCount
likeCount
favoriteCount
commentCount
player
embedHtml
topicDetails
topicCategories
recordingDetails
Notice that part recordingDetails has no fields listed. That doesn't mean it has no fields. It means that none of the videos for the IDs submitted have recordingDetails in their data. That is why I said at the beginning that what I've got is a partial list. It is only based on the data retrieved for those three videos. Another example of this issue is that only two of the three videos submitted have a commentCount in their data. If none of them had data for that field, then I would not know about the existence of that field from this exercise.
So there's my partial list of public fields for videos. Can someone give us a better answer pointing to documentation of all the fields for videos, channels, and playlists?
I need get a list of most viewed music video on Youtube.
I used this API:
https://youtube.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular®ionCode=US&videoCategoryId=10&key=[YOUR_API_KEY]
By default regionCode is US, I want get results by global.
Can someone help me?
You can't really using using the chart means you must include a reagion and the default is the USA.
string
The regionCode parameter instructs the API to select a video chart available in the specified region. This parameter can only be used in conjunction with the chart parameter. The parameter value is an ISO 3166-1 alpha-2 country code.
remove ®ionCode=US Should be the same as US
GET https://youtube.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular&key=[YOUR_API_KEY]
You would have to query EACH region and take the videos with the highest cumulative viewCount over all regions. This would be difficult as different regions will have different music videos that are most popular. Unfortunately the API doesn't have a global regionCode option.
It is possible?
I read the documentation, there are examples of receiving the number of views by country, but I need the number of views by city.
regionCode string
The regionCode parameter instructs the API to return search results for videos that can be viewed in the specified country. The parameter value is an ISO 3166-1 alpha-2 country code.
The YouTube API only supports searching by region code that being ISO 3166-1 alpha-2 country code
No you cant search by city.
I need to get daily uploaded videos in a playlist so thought to get videos for a playlist sorted by published date.
So is there any option to pass published date while fetching data for playlist?
I tried 2 options
option 1 )
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=15&playlistId=PLP-nGFpz3fa_boeLhG4m0Ie_8vmCvp5oH&key={YOUTUBE_API_KEY}
does result return from this URL is in sorted order? I found its not in sorted order.
Can I pass some date parameters related to date in this or some sort related parameters?
option2 )
I tried using "Youtube Search API"
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list
here we have date option but only can pass channelId not playlistId.
So can we pass playlistId in search API to get all videos for playlist?
Is there any other way which I can use?
Thanks
The PlaylistItems:list does not have any way to order results - the playlist order is returned in the order specified by the owner. Nor does Search:list allow you to specify a playlist.
Does the playlist owner add new videos to the beginning or end of the playlist? If the beginning, you could try fetching the first X videos and comparing the publish date to the current date.
Looking at the guide using Videos.list, nowhere does it mention that this feature is available, where the list is readily sorted upon return of the response body. Try putting the results in a container first where you will implement your own comparison of dates to sort the items. This SO thread seems to confirm this.
Is there any way to have updated lists of top 100 videos of youtube by genre and/or by country!
Any kind of resources like json files or xml.
You'll want to use the chart parameter of the videos.list endpoint. Set the chart to mostPopular, and then include a regionCode parameter and videoCategoryId parameter for further narrowing down. For example,
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular®ionCode=UA&key={YOUR_API_KEY}
Will retrieve the 5 most popular videos in the Ukraine.
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&maxResults=25®ionCode=DE&videoCategoryId=1&key={YOUR_API_KEY}
Will retrieve the 25 most popular videos in Germany that relate to Film/Animation. And so on.
Note that if you don't include a videoCategoryId parameter, it will return results from all categories. If you don't include a regionCode, it returns the most popular videos across all regions. You can only set videoCategoryId to a value that's valid in the region you're searching in (you can use the videoCategories.list endpoint to find valid categories for regions, languages, etc.)