how to get number of views: Youtube analytics Report query - youtube-api

_analyticService = new YoutubeAnalyticsService(_authenticator = CreateAuthenticator()); ... var result = _analyticService.Reports.Query("channel==myChannelCode", "2013-01-01", "2013-02-02", "views").Fetch();
I have created a new Youtube analytic Service and I have sent the server a query.
My goal is to get the number of views the user has on his videos.
How do I use result to do this?

In your request
_analyticService.Reports.Query("channel==myChannelCode", "2013-01-01", "2013-02-02", "views").Fetch();
you only fetch the views between 1 January to 2 February. To get the full viewcount you would need to get the lifetime view count, try to specify a start and end date that is far away, like start-date=2005-01-01 and end-date=2100-01-01.
You also probably want to specify a filter with the video id of the video you are looking for, like filter=video==_iwmv6644dA Note also that the view count returned by the api don't seem to get updated as quick as the one on the watch page, so may therefore not be exactly the same.
However, this request works well to get the view count for one of my videos:
https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUCYHMS8hN8s49F93iJuEgG6w&start-date=2005-01-01&end-date=2100-01-01&metrics=views&filters=video%3D%3D_iwmv6644dA&key={YOUR_API_KEY}

Related

Get Video Views for Group of YouTube Videos

I can get a list of videos from a channel I'm querying. I have most of the information I need in an existing api call, but I'd really like to also get the number of times each video has been viewed.
My current query gives me 50 results:
https://www.googleapis.com/youtube/v3/search?part=id,snippet&key=' . $key . '&channelId=' . $channelId . '&order=date&maxResults=50&publishedBefore=' . $publishedBefore
I read I can get viewCounts through the API by providing a video id. But that's one at a time. I'm hoping I can ammend my query above to also output the viewCounts to make 1 query instead of 51 queries.
I have a part attribute that I can set to "a comma-separated list of one or more search resource properties that the API response will include." The examples I've seen have "id,snippet", but can I specify a value that will provide how many times the video has been viewed? I can't find a list of search resource properties.
Also, is there a way to view a channel's "hottest" or "trendiest" videos that they currently have?
You can make one single request which get statistics from youtube API. You need to call API like this
https://content.googleapis.com/youtube/v3/videos?id=Ks-_Mh1QhMc,Cc0KYU2j0TM4,CeIho2S0ZahI&part=statistics&key={APIKEY}
In this request I am getting data from 3 videoId, you can get upto 50 videos at a time.

youtube v3 api : get all live streaming playlist ids of a channel

I have two "Live streaming/live broadcast saved playlists" in following youtube channel --> https://www.youtube.com/user/swaminarayanlive.
I am trying to retrieve all the "live streaming / live broadcast playlists" of a channel using new youtube v3 api by using the below link-->
https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCBkNpeyvBO2TdPGVC_PsPUA&key={YOUR_API_KEY}
here i can get the info of playlists which are not live streams or live broadcast. and not able to get the same for the live one.
Please help me how can i get that for live one using youtube v3 api
I was researching another issue with the API when finding this, and when I saw that this was never resolved, I decided to look into it. It turns out that this is related to that other issue.
The YouTube API v3 lacks support for saved playlists. The channel swaminarayanlive did not create the playlists, only saved them from the channel BhujMandir.
The workaround in your case would be to retrieve the playlists of BhujMandir and extract the response snippets with "title" parameters containing the word "Live".
You would need to go through the pages and search each one for this, since there is a limit to how many results an API response can show at once. Currently it's 50.
So, you would use the following to get the first page of playlistItems:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&key={YOUR_API_KEY}
This will return an API response containing the properties "kind" (which will have the value "youtube#playlistListResponse") and "etag". If there are more than 50 results, there will also be a "nextPageToken" property. (On a page that is not the first, there would also be a "prevPageToken" property.)
After these properties, there are two blocks. One called "pageInfo", containing info about how many results (playlists) there are and how many are shown per page, and one block called "items", containing the resulting playlistItems.
You would look through the items block for any playlistItem with a title property (which is a string) containing the substring "Live" and get the id properties of those. You would then look on the next page by using the nextPageToken's value in a new HTTP request, like so:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&pageToken=[nextPageToken_value_here]&key={YOUR_API_KEY}
As of now, the two playlists you're looking for are on the pages with tokens CJYBEAA and CMgBEAA.
I think that where is the {YOUR_API_KEY} you should change this code and insert the name of your application program interface

YouTube Content ID API : AssetSearch Issue

I am working on YouTube Content ID API to fetch assests which are added today.
First of all I try to explore API on YouTube Content ID API explorer and then find asset search suitable for my criteria.So I provided the required parameters and got the response but response include only 25 results each time so I used NextPageToken
recived from response to get next assests,so far so good ,but for all this responses I noticed the ResultsPerPage varies for each request which confused me.As I assumed that ResultsPerPage indicates the all assests for the particular content owner and considering this I decided to code but now I'm unable to decide how should procced.
Can any one help me to understand this
Both the totalResults and ResultsPerPage are not reliable, according to employees at YouTube. You can only rely on the data that comes through. You can verify this with your TAM/Partner Manager.
In order to get the real count of your assets (I'm assuming you're using AssetSearch?), you have to keep paginating until there's no "nextPageToken' in the response, and count your results.
By the way, if you set the parameter "maxResults=50" in your request, you'll get 50 per page (until there's less than 50 left to display, which should only happen on the last page, given that you have a number of assets not divisible by 50).

Instagram and iOS. get photo with a lot of likes with current user

I am using Instagram api
My query is
api.instagram.com/v1/users/[USER_ID]/media/recent?count=3818
I get only 33 photos that is ordered by date
But,I need to load all the users photo which has more likes
what am I missing here ?
You can use Pagination.See http://instagram.com/developer/endpoints/ for information on pagination. You need to subsequentially step through the result pages, each time requesting the next part with the next_url that the result specifies in the pagination object.
From instagram
pagination
Sometimes you just can't get enough. For this reason, we've provided a
convenient way to access more data in any request for sequential data.
Simply call the url in the next_url parameter and we'll respond with
the next set of data.
{
...
"pagination": {
"next_url": "https://api.instagram.com/v1/tags/puppy/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d&max_id=13872296",
"next_max_id": "13872296"
} }
On views where pagination is present, we also support the "count"
parameter. Simply set this to the number of items you'd like to
receive. Note that the default values should be fine for most
applications - but if you decide to increase this number there is a
maximum value defined on each endpoint.

YouTube API "published" filter doesn't seem to work

I'm trying to use the YouTube API to return videos that were recently published, but the filter I'm using doesn't seem to work as expected.
This API call only returns two videos whereas there should be tons more that were published after March 1st:
https://gdata.youtube.com/feeds/api/videos?q=&fields=entry[xs:dateTime(published)%20%3E%20xs:dateTime('2013-03-01T12:00:00.000Z')]
However, if I add a query string, then many more results are returned. For example:
https://gdata.youtube.com/feeds/api/videos?q=surfing&fields=entry[xs:dateTime(published)%20%3E%20xs:dateTime('2013-03-01T12:00:00.000Z')]
Anyone know why? Is there another approach I should be using to just get me the latest videos published regardless of query string?
I understand your confusion, but that's not what the fields= parameter is used for. The documentation should hopefully clear things up, but to summarize, using fields= in that manner is equivalent to making a request without the fields= parameter and then filtering the results of that request so that it only includes the entries that match your filter.
So if your request without fields= would normally return 25 specific videos, adding fields= to it will give you a response that includes somewhere between 0 and 25 videos—all the non-matching videos are filtered out.
You can request a feed of recently published videos without any other filters using http://gdata.youtube.com/feeds/api/videos?v=2&orderby=published

Resources