is there Youtube API support to retrieve my statistics like if I watched it or not - youtube-api

is there Youtube API support to retrieve my statistics like if I watched it or not, how many times I played it or retrieve my view history? I spend some time going thru the Youtube Data API but no luck.

You can use YouTube API - ViewCount to retrieve the number of times the video has been viewed. You can retrieve the information in the client side or in the server side using some of the libraries.
You need to retrieve the video, from there you can retrieve the statistics part contains the viewCount
Sample request:
GET https://www.googleapis.com/youtube/v3/videos?part=statistics&id=Q5mHPo2yDG8&key={YOUR_API_KEY}
Response:
200 OK
- Show headers -
{
"kind": "youtube#videoListResponse",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/dZ8K81pnD1mOCFyHQkjZNynHpYo\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"id": "Q5mHPo2yDG8",
"kind": "youtube#video",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/4NA7C24hM5mprqQ3sBwI5Lo9vZE\"",
"statistics": {
"viewCount": "36575966",
"likeCount": "127569",
"dislikeCount": "5715",
"favoriteCount": "0",
"commentCount": "20317"
}
}
]
}

Related

YouTube API Returns Wrong SubscriberCount

I have two channels examples:
https://www.youtube.com/channel/UC56eaiucsjSfKgevcaGcn2w => real sub 150k
https://www.youtube.com/channel/UC-2Zibu3OGJdIisYaODXhbQ => real sub 208k
This is what was returned from the Channels list endpoint:
{
"kind": "youtube#channelListResponse",
"etag": "wVkhi3RvF1ayB9ou0W6KZcanGZE",
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "QI30osPYB_sy-uwNipgDhEPKRso",
"id": "UC56eaiucsjSfKgevcaGcn2w",
"statistics": {
"viewCount": "17359612",
"subscriberCount": "320",
"hiddenSubscriberCount": false,
"videoCount": "26"
}
},
{
"kind": "youtube#channel",
"etag": "IjATUKKNgPUxmtHQWicg_r22hqc",
"id": "UC-2Zibu3OGJdIisYaODXhbQ",
"statistics": {
"viewCount": "1723670",
"subscriberCount": "18",
"hiddenSubscriberCount": false,
"videoCount": "1"
}
}
]
}
When you go to the links above, and navigate through the channel, I noticed that the channel Id changes and the API returns the correct sub count for the new Id.
I am unsure how a unique video Id can be linked to more than one channel, What kind of channels are these? merged, linked, or something else? and how does the user do this?
"click on the same link you gave me, then click on the first video" there isn't any video on my side. Using PlaylistItems: list with the channel uploads playlist I get 26 videos and the first one is hVyJsXCXyuo. Even if all retrieved videos are unavailable, for the first video I indeed see that the channel real subscribers count is 150k and if I click on the channel name I get redirected to another channel that is UC4LyPYXnF07KF97Nb8vE_Pg which indeed has 150k subscribers.
Then you can use Channels: list to get the correct subscriber count using id=UC4LyPYXnF07KF97Nb8vE_Pg cf https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UC4LyPYXnF07KF97Nb8vE_Pg&key=YOUR_API_KEY
Note that under a video the channel id you are redirected to seems to differ if you click on the channel avatar or the channel name on a desktop. The following redirection are done if you are on a phone or a computer and if you click on the channel avatar or channel name:
Phone:
Name: UC56eaiucsjSfKgevcaGcn2w
Avatar: UC56eaiucsjSfKgevcaGcn2w
Computer:
Name: UC4LyPYXnF07KF97Nb8vE_Pg
Avatar: UC56eaiucsjSfKgevcaGcn2w

YouTube Data API - Empty "items" list from Activities:list

I'm trying to get user activity (liking, subscribing, etc.) through YouTube's Data API. However, when I send a GET request here: https://youtube.googleapis.com/youtube/v3/activities?part=snippet%2CcontentDetails&maxResults=25&mine=true&key=[MY API KEY]
I get a 200 response but with the "items" empty:
{
"kind": "youtube#activityListResponse",
"etag": "Gt78OtFG_qGDXWi8-LJKjdLhoCY",
"items": [],
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 25
}
}
I know that the account I linked it to has activity, so I'm confused by it's not returning any information. Any assistance would be appreciated.

How to get subscriber count and videos count for a given YouTube channel?

Until now I've been using this URL to retrieve subscriber count for a channel:
http://gdata.youtube.com/feeds/api/users/<channel_id>?v=2&alt=json
And this URL to get channel videos count:
https://gdata.youtube.com/feeds/api/users/<channel_id>/uploads?v=2&alt=jsonc&max-results=0
But from this day Google discontinued using it's v2 API and I can't find replacement options for this data.
You're going to want to use the Channels/list endpoint as pass in statistics for the part parameter.
Request:
HTTP GET: GET https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={YOUR_API_KEY}
Response (with id=UCt7iVnJwjBsof8IPLJHCTgQ):
{
"kind": "youtube#channelListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WNxXCvycTyqTjTn9sLJ5toVjBRY\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/jijTuA_iWn2Kv9aRnqeAWNAcQ6I\"",
"id": "UCt7iVnJwjBsof8IPLJHCTgQ",
"statistics": {
"viewCount": "796662",
"commentCount": "20",
"subscriberCount": "257",
"hiddenSubscriberCount": false,
"videoCount": "126"
}
}
]
}
You can pass in a comma-separated list of Channel IDs for the id parameter. Because I only passed in one id, the first object of the items array will have the values you need. Get the object for the subscriberCount and videoCount values in the statistics dictionary for the data you want.

YouTube: Is there a way I can get the list of videos viewed by the user?

I want to build a video recommender for the user of my Android application. I have Google OAuth to login in my app. Can I get the data about the videos viewed by the user of my app on YouTube?
This is a two-step process with the v3 API:
1. Hit Channels.list method with an OAuth2 request of the logged in user. Pass in contentDetails for the part value and mine = true.
Request:
HTTP GET: https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&key={YOUR_API_KEY}
Response:
{
"kind": "youtube#channelListResponse",
"etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/41Jk5t11dHi2JfUXrF4jZJhaQnE\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/wfaiZMzCHBlyq_ZFJU5pMR4q4sg\"",
"id": "UCt7iVnJwjBsof8IPLJHCTgQ",
"contentDetails": {
"relatedPlaylists": {
"likes": "LLt7iVnJwjBsof8IPLJHCTgQ",
"favorites": "FLt7iVnJwjBsof8IPLJHCTgQ",
"uploads": "UUt7iVnJwjBsof8IPLJHCTgQ",
"watchHistory": "HLt7iVnJwjBsof8IPLJHCTgQ",
"watchLater": "WLt7iVnJwjBsof8IPLJHCTgQ"
},
"googlePlusUserId": "103927393533363914063"
}
}
]
}
The object for the watchHistory key is the playlistId of your viewing history. Keep this value for use in step 2.
2. Hit the playlistItems.list method with the watchHistory playlistId from step 1.
Request:
HTTP GET: https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&id=HLt7iVnJwjBsof8IPLJHCTgQ&key={YOUR_API_KEY}
Response:
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/ozXLhcdE2ZWgvJu3ywqxtfQeL7o\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": [
]
}
The contents of the items array will have your viewing history.
Please note that there is a known bug with the v3 API where your history will not be returned. This has been reported internally to YouTube's team and was supposed to be fixed two years ago.

Get daily view counts for all video of a given channel on Youtube Analytics

I'm trying to use the Youtube Analytics API to gather daily view counts for all the videos in my channel. It seems like the video dimension throttles the result at top 10 only. Is there anyway I could get daily view count for all my videos?
At the moment you cannot get metrics for all videos via Analytics API directly. First you need to fetch the ids of all your videos and then request Analytic's data for each. I managed it this way:
Get the playlist ID for your uploaded videos via Data API https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&maxResults=25&access_token=[TOKEN]. Gives you this result:
{
"kind": "youtube#channelListResponse",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/SAGx1pv6myGXge51dmywGW81h8o\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/g5zJtodBJms3CAfwF_ar2nVgJjU\"",
"id": "[id]",
"contentDetails": {
"relatedPlaylists": {
"likes": "[id]",
"favorites": "[id]",
"uploads": "[id]",
"watchHistory": "[id]",
"watchLater": "[id]"
},
"googlePlusUserId": "[id]"
}
}
]
}
Get all ids of your uploaded videos with the upload playlist id via Data API: https://www.googleapis.com/youtube/v3/playlistItems?part=id&pageToken=&playlistId=[UPLOADID]&maxResults=50&access_token=[TOKEN]. Note: You have to page through the results with nextPageToken.
With the collected video ids you can make a batch request to the Analytics API https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==mine&start-date=2014-12-29&end-date=2015-01-05&metrics=views,likes&dimensions=video,day&filters=video==[videoId],[videoId],[videoId],[...]&sort=video&access_token=[TOKEN] Note: You can batch up to 200 Video Ids.

Resources