Overall Goal: To report possible subscribers who are not active on my YouTube channel.
I'm reading through the YouTube Data API (v3) trying to understand how to retrieve the actual ids who watched a specific video. I know you can get the number of views, but I don't see any call/response that shows you the subscriber ids. Has anyone done this?
So far what I gathered from the docs and Google searching is that this was possible using the Watch History of a subscriber, but that's been deprecated.
Thanks in advance!
So I do not believe it's possible to get IDs of users who have watched certain videos but I have a workaround for my use case; reporting inactive subscribers. This is not the best but it'll get me somewhere.
YouTube's API is very limiting now, but by calling the Subscriptions API
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet%2CcontentDetails&mySubscribers=true&key=[YOUR_API_KEY]
I am able to get all subscribers with their channel IDs. Then after saving their IDs, I can check each one's statistics by making this call:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=[SUB_ID]&key=[YOUR_API_KEY]
which I receive a response like this:
{
"kind": "youtube#channelListResponse",
"etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/AZpZT_vQrY3UTi57ia_QqrKdc8c\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"something\"",
"id": "[SUB_ID]",
"statistics": {
"viewCount": "0",
"commentCount": "0",
"subscriberCount": "1",
"hiddenSubscriberCount": false,
"videoCount": "0"
}
}
]
}
Using this response (see "statistics"), I am making a generalization that if the subscriber has no comments AND no videos, then it's a safe bet that they are not active.
Related
Youtube recently rolled out handles feature where they gave users youtube.com/#xxx type usernames, when visited these URLs show user's channel but I can't find any documentation or reference in API repositories.
How to extract youtube user channel ID from their handle?
One more time YouTube Data API v3 doesn't provide a basic feature.
I recommend you to try out my open-source YouTube operational API. Indeed by fetching https://yt.lemnoslife.com/channels?handle=#HANDLE you will get the YouTube channel id you are looking for in item["id"].
For instance with the YouTube channel handle #WHO, you would get:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC07-dOwgza1IguKA86jqxNA"
}
]
}
I need to get metrics (primarily total live views and total/avg live view duration) for YouTube LIVE events. I'm having trouble with both v2 and v3 APIs.
I can schedule and stream through the API fine, and I'd like to pull the analytics as soon as the broadcast ends to roll up some reports.
Question
How can I get total or average live view duration from the v3 API?
Or, how can I properly query the v2 reports API for Live events to get non-zero data back?
More Details On Current Attempts
Here are the types of queries I've tried:
YouTube v3 API:
https://www.googleapis.com/youtube/v3/videos?
id={live_video_id}&
part={"statistics,liveStreamingDetails"}&
access_token={access_token}
{
"kind": "youtube#videoListResponse",
"etag": "...",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "...",
"id": "..",
"statistics": {
"viewCount": "38",
"likeCount": "1",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "0"
},
"liveStreamingDetails": {
"actualStartTime": "2018-10-11T12:01:23.000Z",
"actualEndTime": "2018-10-11T14:00:12.000Z",
"scheduledStartTime": "2018-10-11T12:00:00.000Z",
"scheduledEndTime": "2018-10-11T14:00:00.000Z"
}
}
]
}
I can get statistics.viewCount count here, but there's no way to get the avg/total time watched.
YouTube v2 Reports API:
https://youtubeanalytics.googleapis.com/v2/reports?
startDate={"2017-01-01"}&
endDate={time.Now().Add(24*time.Hour).Format("YYYY-MM-DD")}&
filters={"video==" + live_video_id}&
metrics={"views,estimatedMinutesWatched"}&
ids={"channel==MINE"}&
access_token={accessToken}
{
"kind": "youtubeAnalytics#resultTable",
"columnHeaders": [
{
"name": "views",
"columnType": "METRIC",
"dataType": "INTEGER"
},
{
"name": "estimatedMinutesWatched",
"columnType": "METRIC",
"dataType": "INTEGER"
}
],
"rows": [
[
0,
0
]
]
}
This query would seem to give the metrics I need, but it's all 0s, even when v3 returns non-zero views.
TL;DR YouTube Reports API v2 doesn't update the metrics quite often for less popular live streams.
This is how I reached this conclusion...
I fetched the views, estimatedMinutesWatched of an old video from my channel. While both these APIs worked, the view count returned by the YouTube Reports API v2 was not accurate and was lagging behind the YouTube Data API v3.
Next, I ran a Livestream (unlisted) and engaged on the stream with a few other accounts. None of these engagements (like, subscribe, views) was shown in the Reports API v2 nor in YouTube Studio Analytics. This proves that the "rows": [[0,0]] returned by YouTube Reports API v2 is completely normal. But surprisingly, the Data API v3 did return the correct metrics as you pointed out.
For live streams with large audience and engagement, the Reports API may work perfectly fine.
Since the Data API doesn't provide watch times of any sort, your best bet would be to use both these APIs in conjunction, Data API v3 to fetch the basic metrics like views, likes,.. and the Reports API v2 for more sophisticated metrics.
Tip: If you are interested in displaying the live stream metrics later on, you can use the dimension=liveOrOnDemand parameter and filter the metrics to the LIVE stream alone.
I'm attempting to access https://www.youtube.com/channel/UC7LoiySz7-FcGgZCKBq_2vQ via the YouTube Data API v3 however am not able to load channel by id:
https://content.googleapis.com/youtube/v3/channels?part=snippet&id=UC7LoiySz7-FcGgZCKBq_2vQ&key=<omitted>
{
"kind": "youtube#channelListResponse",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/Rk41fm-2TD0VG1yv0-bkUvcBi9s\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 0
},
"items": []
}
other channels that this same error occurs for:
https://www.youtube.com/channel/UCzwNZaQ2qyZw0n3xOSNoXaQ
https://www.youtube.com/channel/UC0iFwqagVPP6pXiDwYU170g
Your channels are of type hidden. This is the expected outcome. Unhide it and work your way from there.
Delete or hide your YouTube channel:
You can hide content from your YouTube channel and choose to re-enable
it later. When you hide content, your channel name, videos, likes,
subscriptions, and subscribers will be made private.
All your comments and replies will be permanently deleted. Your
account data on other Google properties will not be removed.
One more time YouTube Data API v3 doesn't provide a basic feature.
I recommend you to try out my open-source YouTube operational API. Indeed by fetching https://yt.lemnoslife.com/channels?part=status&id=CHANNEL_ID, you will get the YouTube channel status message you are looking for in item["status"].
For instance with this channel id UC7LoiySz7-FcGgZCKBq_2vQ you would get:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC7LoiySz7-FcGgZCKBq_2vQ",
"status": "This channel is not available."
}
]
}
For a suspended YouTube channel such as UCF_UozwQBJY4WHZ7yilYkjA, you would get for status: "This account has been terminated due to multiple or severe violations of YouTube's policy on nudity or sexual content.".
For a normal channel, such as UC4QobU6STFB0P71PMvOGN5A, you would get for status: null.
I am trying to retrieve all comments to a video with all replies, however, using the Test It interface (or the Java library) I have not been able to retrieve all comments - I have following two examples, when I have failed:
Example 1
The example video and comment is https://www.youtube.com/watch?v=xCLy2DZdXhY&lc=z12ei1s5gs2mc303523qsdigcxmphhlrd04
When I retrieve the comment using
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&id=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
I receive:
And note the "totalReplyCount": 2, line.
However, when I try to obtain all replies using the parentId:
GET https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
I receive an empty response:
Remarks
I have read Youtube Data API v3: commentThread call doesn't give replies for some comment threads , however, it does not provide me the answer as I do use the comments list with parentId and I am still not getting any replies.
Even if I try the not recommended way - using the part snippet,replies, I do not get any replies:
Request:
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&id=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
However, if I do not specify the comment thread by its ID and specify that I want all comment threads for the video:
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&videoId=xCLy2DZdXhY&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
Then voila - The comment thread is now with those two replies:
Why do I receive the replies now and not when I either specify the replies by their parentId or when I specify the comment thread by its id?
Moreover, if I take the (weird) id of one of the replies and try to obtain the comment with this reply, I will receive empty response:
GET https://www.googleapis.com/youtube/v3/comments?part=snippet&id=z12ei1s5gs2mc303523qsdigcxmphhlrd04.1443381718685326&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
Example 2
This problem is a bit different.
I have a video https://www.youtube.com/watch?v=-c76GeR2IWg with 7 comments (6 of them are top levels). When I try to obtain all top level comments related to this video I receive only 4 of them.
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&videoId=-c76GeR2IWg&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
One of the missing comments in the response is https://www.youtube.com/watch?v=-c76GeR2IWg&lc=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k .
When I train to obtain comment thread with this id, I do obtain the comment thread:
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&id=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
And also, when I try to obtain the replies for this comment (there should be 1 reply) I receive an empty response:
GET https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
Remarks
For both examples, the number of comments is less than the size of the page. For this simple example, I have skipped pagination and chose examples with only a few comments, in the real application I use the pagination but I do not get more results.
I do not really understand how is the YouTube and G+ integrated together, thus this might be the issue, however, I was always accesing these videos using only youtube, not checking the users' G+ page, thus I would say that this should not be the case.
Similar questions on SO:
How can I see all the comments with the Youtube API? This is about V2 API, thus no use for me.
Youtube Data API v3: commentThread call doesn't give replies for some comment threads This question is very similar and raises similar problems, however, it is exactly the other way around - The author does not receive all replies using the commentThread replies (which is agreeing with the documentation), however, the proposed solution is "Use the comments.listcall instead and specify the commentThread's ID for the parentId." - which is exactly what does not work for me.
YouTube Data API v3 Comment Thread Discrepency The author forgot about pagination.
YouTube Data API v3 - Comment threads request doesn't return all comments Similar question, yet without any answer.
When I do the following via HTTP request:
https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
I get the following response:
items": [
{
"kind": "youtube#comment",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/aOipn7OKd9ibVua9TWdtD2vJJgI\"",
"id": "z12ei1s5gs2mc303523qsdigcxmphhlrd04.1443381718685326",
"snippet": {
"textDisplay": "JM",
"parentId": "z12ei1s5gs2mc303523qsdigcxmphhlrd04",
"authorDisplayName": "Asia Price",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCtUuxM3_g2hWA7qr17d85RQ",
"authorChannelId": {
"value": "UCtUuxM3_g2hWA7qr17d85RQ"
},
"authorGoogleplusProfileUrl": "https://plus.google.com/100662746258967935686",
"canRate": false,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2015-09-27T19:21:58.685Z",
"updatedAt": "2015-09-27T19:21:58.685Z"
}
},
{
"kind": "youtube#comment",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/NtowtHGdhytzw9YY9RxUopEgoTA\"",
"id": "z12ei1s5gs2mc303523qsdigcxmphhlrd04.1443365800258222",
"snippet": {
"textDisplay": "0",
"parentId": "z12ei1s5gs2mc303523qsdigcxmphhlrd04",
"authorDisplayName": "FAY Fay",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UC5b4dTxK4ae_roaMWMYpglQ",
"authorChannelId": {
"value": "UC5b4dTxK4ae_roaMWMYpglQ"
},
"authorGoogleplusProfileUrl": "https://plus.google.com/100517618639903741268",
"canRate": false,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2015-09-27T14:56:40.258Z",
"updatedAt": "2015-09-27T14:56:40.258Z"
}
}
I get the same results when I use the API explorer.
For your second example,
https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
gives me
"items": [
{
"kind": "youtube#comment",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/UBoqDwv8bg8xZpbIepzI_M5gp9o\"",
"id": "z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k.1409319325542384",
"snippet": {
"textDisplay": "Ahoj děkuju :) jo máš fajn videa :) ",
"parentId": "z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k",
"authorDisplayName": "Gumičkování s Péťou",
"authorProfileImageUrl": "https://lh4.googleusercontent.com/-VJce_PtJx70/AAAAAAAAAAI/AAAAAAAAABI/dabMtsy0haY/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCAyuADHtiVTpiAbt2VVQhtQ",
"authorChannelId": {
"value": "UCAyuADHtiVTpiAbt2VVQhtQ"
},
"authorGoogleplusProfileUrl": "https://plus.google.com/101894467260220798842",
"canRate": false,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2014-08-29T13:35:25.542Z",
"updatedAt": "2014-08-29T13:35:25.542Z"
}
}
It might be an issue with your request or API key. Try making a new one and using that.
I am in the middle of developing a YouTube client using YouTube Data v3 API, and is playing with two different channels observed:
Go Pro Channel: https://www.youtube.com/user/GoProCamera/videos
YouTube curated Sports Channel: https://www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw/videos
In Go Pro channel, I can also choose a video filter: "Uploads", "Liked" and "Posted Videos". I am much puzzled by the "Uploads" and "Posted Videos" filter, which from my observation, on this channel, they are giving the same result. But in YouTube curated sports channel, there is only "Posted Video" option there.
For the past hours, I can not find any definitive explanation from YouTube v2/v3's API documentation, and what is more bothering me is, I can not find any API to retrieve the video entry data in those channels.
For Go Pro Channel, I could at least rely on the method mentioned here to get uploaded video: How do I get a list of uploaded videos for a certain channel with the new YouTube Data API (V3)?
But for curated channels, even this method does not work, the playlist given in channel query result is always empty:
Request
GET https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails%2Csnippet&id=UCEgdi0XIXXZ-qJOFPf4JSKw&key={YOUR_API_KEY}
Authorization: Bearer ya29.dwCMU6xpf5N9AxwAAABgIM94lgv7jGHw0h0oEjs6uZUdPFO28CDYhbvgXdKTjw
X-JavaScript-User-Agent: Google APIs Explorer
Response
200 OK
- Show headers -
{
"kind": "youtube#channelListResponse",
"etag": "\"WFPuK6TsnblcGPcnMex79s42ynQ/qpdedwjxXQ-COrk0dODO-8DTAx0\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"WFPuK6TsnblcGPcnMex79s42ynQ/TP96YXZ0G4VPdQ7fd2IYgW79rW0\"",
"id": "UCEgdi0XIXXZ-qJOFPf4JSKw",
"snippet": {
"title": "Sports",
"description": "Sport is all forms of usually competitive physical activity which, through casual or organised participation, aim to use, maintain or improve physical ability and skills while providing entertainment to participants, and in some cases, spectators. Hundreds of sports exist, from those requiring only two participants, through to those with hundreds of simultaneous participants, either in teams or competing as individuals. Sport is generally recognised as activities which are based in physical athleticism or physical dexterity, with the largest major competitions such as the Olympic Games admitting only sports meeting this definition, and other organisations such as the Council of Europe using definitions precluding activities without a physical element from classification as sports. However, a number of competitive, but non-physical, activities claim recognition as mind sports.\nThis channel was generated automatically by YouTube's video discovery system.",
"publishedAt": "2013-12-15T20:39:04.000Z",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/hq1.jpg"
}
}
},
"contentDetails": {
"relatedPlaylists": {
"likes": "LLEgdi0XIXXZ-qJOFPf4JSKw",
"uploads": "UUEgdi0XIXXZ-qJOFPf4JSKw"
}
}
}
]
}
--
Request
GET https://www.googleapis.com/youtube/v3/playlistItems?part=id%2CcontentDetails%2Csnippet&playlistId=UUEgdi0XIXXZ-qJOFPf4JSKw&key={YOUR_API_KEY}
X-JavaScript-User-Agent: Google APIs Explorer
Response
200 OK
- Show headers -
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"WFPuK6TsnblcGPcnMex79s42ynQ/0ky7gu-r2KEON6-qkmzKhU77B-Q\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": [
]
}
It seems to me this is a dead end now, so is there any way to get videos from this kind of curated channels?
If you've already got the channel ID of the curated channel, you can just use the search endpoint to get the videos; for example, this API call will receive the 50 most recent videos added to YouTube's sports channel:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCEgdi0XIXXZ-qJOFPf4JSKw&maxResults=50&order=date&key={YOUR_API_KEY}