How to get video metrics for each video for each day - youtube-api

I am trying to get video metrics for each video under my channel using Java SDK.
videoMetrics = analytics.reports()
.query("channel==" + channelId, video_start_date, video_end_date, "views,comments,likes,dislikes,estimatedMinutesWatched")
.setDimensions("day")
.setSort("-estimatedMinutesWatched")
.setFilters("video==" + videoId)
.setFilters("country==US")
.execute();
This request not providing the metrics for each video on a particular day. Can anyone suggest the issue and solution in the code.

You're looking for reports.query.
The YouTube Analytics
API's
reports.query method lets you retrieve many different Analytics
reports. Each request uses query parameters to specify a channel ID or
content owner, a start date, an end date, and at least one metric. You
can also provide additional query parameters, such as dimensions,
filters, or sorting instructions.
Metrics are individual measurements of user activity, such as video
views or ratings (likes and dislikes). Dimensions are common criteria
that are used to aggregate data, such as the date on which the user
activity occurred or the country where the users were located. Filters
are dimension values that specify the data that will be retrieved. For
example, you could retrieve data for a specific country, a specific
video, or a group of videos.

Related

Youtube api to get advance statistics per video per day

I have been trying to get the video list of our youtube channel and advance statistics like avg view duration, subscribers gained, watch time, etc.
These statistics do exist in Youtube analytics Web GUI. But I could not find how I can implement that per video via API.
I have tried youtubeAnalytics.reports.query API - but unable to get the advanced statistics.
with these parameters
ids : channel==MINE
filter = video==
startdate: 2019-02-15
enddate: 2019-02-20
metrics likes- dislikes avgviewDuration,
dimension: day
and other try with
dimension day,video
I am getting null data or query not implemented.

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 Analytics API channel: The response has no rows parameter

When using the API for retrieving aggregated metrics for the channel's content the report returns a single row of data that contains totals for each requested metric during the specified date
range.
Here's an API Example link.
Sometimes not even account information is received; the object rows is not present in the response but only columnHeaders, even though the account has the appropriate fields populated (I can see it on the profile available on youtube).
I have made the same observations as jay. Somehow some metrics returned no result rows. But for me it turned out that those missing rows were also not available in youtube's Analytics integration.
As you can see, all "Interaktionen (Interactions)" have 0 values, but the "Geteilte Inhalte (shares)" column differs from the rest. It has no values attached. If you click on the metric you get the following notification
It says: "There is no data available at the moment, chose a diffrent time range or wait some more days".
So for me the API data was always corresponding with youtube's analytics integration.

Top 100 youtube videos

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&regionCode=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&regionCode=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.)

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.

Resources