I am trying to get the total likes and dislikes of a company channel youtube using API and php but as for now I get only subscribers , total views, and total videos.Does anybody knows how can I proceed, I need to push all these informations to a DB.
"statistics": {
"viewCount": "793781",
"commentCount": "0",
"subscriberCount": "3861",
"hiddenSubscriberCount": false,
"videoCount": "149"
}
Look at the documentation : you can use the getRating endpoint like this :
GET https://www.googleapis.com/youtube/v3/videos/getRating
And you will get somethings like this
{
"kind": "youtube#videoGetRatingResponse",
"etag": etag,
"items": [
{
"videoId": string,
"rating": string
}
]
}
Related
If I make a curl request for this URL:
https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=UC_x5XG1OVP6uZZ5FSM9Ttw&key=...
I'll get the output as:
{
"kind": "youtube#channelListResponse",
"etag": "J801W-IQ15sDpy3GjDfjlUgoVxA",
"pageInfo": {
"resultsPerPage": 0
}
}
Does this mean that the YouTube channel doesn't exist?
I don't get any error; how to find whether this is a valid channel or not?
Likewise, I want the list of videos of a given channel. If I make a curl request using this URL:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCIJIhBwx4XjNUtQGZTGSVnA&maxResults=20&order=date&key=[YOUR_API_KEY]
I'll get the output as:
{
"kind": "youtube#searchListResponse",
"etag": "q5r0QewUnrg2C7BdwuxbJxb9b8c",
"regionCode": "IN",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 20
},
"items": []
}
This is a valid channel ID, but I get an empty result, not an error; how to know the search is valid or not?
Question no. 1
For what concerns your first question:
Given a channel ID -- $CHANNEL_ID --, test whether the respective channel exists or not.
I would recommend invoking curl on the following URL:
https://www.googleapis.com/youtube/v3/channels?part=id&fields=items/id&id=$CHANNEL_ID&key=$APP_KEY
Note that invoking the Channels.list endpoint through the URL above -- which contains the parameters part=id and fields=items/id -- will return only the channel's ID.
Although not documented explicitly, tests show that you'll get back from the endpoint the ID you passed on to it, if and only if that channel does actually exist.
For example, in case of your channel ID above -- UC_x5XG1OVP6uZZ5FSM9Ttw --, the API response is trivially empty:
{}
becase this channel does not exist (only have to click on this link to see that yourself).
On the other hand, in case of NBCNews' channel -- UCeY0bbntWzzVIaj2z3QigXg -- the response is:
{
"items": [
{
"id": "UCeY0bbntWzzVIaj2z3QigXg"
}
]
}
showing that indeed this channel is live and kicking.
Question no. 2
For what concerns the second question of your post:
Given a channel by its ID $CHANNEL_ID, do list the videos of that channel.
I recommend you to consult the answer I gave recently to this very question.
In terms of curl, you'll have to invoke the following URL:
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&fields=items/contentDetails/relatedPlaylists/uploads&id=$CHANNEL_ID&key=$APP_KEY
for to obtain that channel's uploads playlist ID. For example, in the case of NBCNews' channel, the API response is:
{
"items": [
{
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUeY0bbntWzzVIaj2z3QigXg"
}
}
}
]
}
Then take out that ID from the JSON response as $PLAYLIST_ID and invoke curl on the following URL repeatedly, implementing pagination:
https://www.googleapis.com/youtube/v3/playlistItems?part=id,snippet,contentDetails,status&maxResults=50&playlistId=$PLAYLIST_ID&key=$APP_KEY.
In case of NBCNews' uploads playlist, the output of the first page would look like:
{
"kind": "youtube#playlistItemListResponse",
"etag": "5DW9uT73DWmJtDoJ-rSw3AqHKpc",
"nextPageToken": "CAUQAA",
"items": [
{
"kind": "youtube#playlistItem",
"etag": "_X3LvLIRvEBM3RetizOGtB03ja0",
"id": "VVVlWTBiYm50V3p6VklhajJ6M1FpZ1hnLjE5NjU4N0NGQkY5M0M3MjI=",
"snippet": {
"publishedAt": "2020-09-12T06:11:59Z",
"channelId": "UCeY0bbntWzzVIaj2z3QigXg",
"title": "Watch NBC News NOW Live - September 11",
"description": "NBC News NOW is live, reporting breaking news and ...",
"thumbnails": {
...
},
"channelTitle": "NBC News",
"playlistId": "UUeY0bbntWzzVIaj2z3QigXg",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "yXO2hQXC5Dw"
}
},
"contentDetails": {
"videoId": "yXO2hQXC5Dw",
"videoPublishedAt": "2020-09-12T06:11:59Z"
},
"status": {
"privacyStatus": "public"
}
},
{
"kind": "youtube#playlistItem",
"etag": "PGyhZonOjiRzqHu7DKDPk6gcMTo",
"id": "VVVlWTBiYm50V3p6VklhajJ6M1FpZ1hnLjY2RTJFNDA4MDA0NDREQTU=",
"snippet": {
"publishedAt": "2020-09-12T02:48:48Z",
"channelId": "UCeY0bbntWzzVIaj2z3QigXg",
"title": "Gaza Sees Spike In Coronavirus Cases, Severe Shortage Of Supplies | NBC News NOW",
"description": "NBC News’ Kelly Cobiella reports on the surge in Gaza ...",
"thumbnails": {
...
},
"channelTitle": "NBC News",
"playlistId": "UUeY0bbntWzzVIaj2z3QigXg",
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "I0lHV0ZVPAs"
}
},
"contentDetails": {
"videoId": "I0lHV0ZVPAs",
"videoPublishedAt": "2020-09-12T02:48:48Z"
},
"status": {
"privacyStatus": "public"
}
},
...
],
"pageInfo": {
"totalResults": 20000,
"resultsPerPage": 50
}
}
Do notice the property nextPageToken within the JSON response text above; the value of this property -- CAUQAA -- would have to be passed to the second invocation of the endpoint as the parameter pageToken=CAUQAA added to the initial URL above.
For to obtain the n-th page, you'll extract the value of nextPageToken from the n-1-th page, for to pass that value to the the n-th URL as pageToken=....
There is no request in the API that will tell you 100% if a channel exits or not.
Even doing a do a video search for the channel wont help you as. If it exists then it would return the videos for that channel, if not then you get back 0 videos.
request
curl \
'https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCMPpVtxOI8RtfurfvCcxgyA&order=date&key=[YOUR_API_KEY]' \
--header 'Accept: application/json' \
--compressed
response
{
"kind": "youtube#searchListResponse",
"etag": "oaf4zpPSG6Ho_cSxZedNhuVhjkw",
"nextPageToken": "CAUQAA",
"regionCode": "DK",
"pageInfo": {
"totalResults": 1721,
"resultsPerPage": 5
},
"items": [
no channel
In the event no channel exists the above code will return total results of 0
{
"kind": "youtube#searchListResponse",
"etag": "opQHhlM-mBA_i0h80B_gmHdKgCE",
"regionCode": "DK",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}
Another option
Another option would be to not use the API at all. Just make a call to against YouTube itself.
If you load this page it loads the actual channel https://www.youtube.com/c/NBCNews However if you try to load https://www.youtube.com/c/lafjdajdskfadkfj it redirects you to https://www.youtube.com/error?src=404 i would think that would be something simple to detect.
We want to get the insights per campaign for multiple campaigns that belong to a specific ad account in a single call.
I am using the following http call and it returns me the correct insights(reach, impressions and clicks) and other data per campaign for the last 30 days only.
https://graph.facebook.com/v3.3/<ad_account>/campaigns?fields=name,status,insights{reach,impressions,clicks}&access_token=<access_token>
How can I use the parameter date_preset so that I will be able to get the insights(reach, impressions and clicks) and other data per campaign for lifetime?
If there is any other way to get the above insights for lifetime without using the date_preset please do not hesitate to advise me how to get them.
We wanted to let you know that our app is written in php.
Because insights is an edge of the campaign object you can apply some filter parameters via dot on that edge, like this:
https://graph.facebook.com/v3.3/<ad_account>/campaigns?fields=name,status,insights.date_preset(lifetime){reach,impressions,clicks}&access_token=<access_token>
Or, if you want to check Insights with the time breakdown (three months, for example) and also take a look on the lifetime summary you can do it like this:
https://graph.facebook.com/v3.3/<ad_account>/campaigns?fields=name,status,insights.default_summary(true).limit(3).date_preset(lifetime).time_increment(monthly){reach,impressions,clicks}&access_token=<access_token>
{
"name": "Campaign Name",
"status": "Campaign Status",
"insights": {
"data": [
{
"reach": "149599",
"impressions": "291917",
"clicks": "13517",
"date_start": "2019-01-11",
"date_stop": "2019-01-31"
},
{
"reach": "265556",
"impressions": "456458",
"clicks": "7915",
"date_start": "2019-02-01",
"date_stop": "2019-02-28"
},
{
"reach": "233641",
"impressions": "331600",
"clicks": "4671",
"date_start": "2019-03-01",
"date_stop": "2019-03-31"
}
],
"paging": {
"cursors": {
"before": "BFR",
"after": "AFT"
},
"next": "next link"
},
"summary": {
"reach": "660772",
"impressions": "1486924",
"clicks": "32484",
"date_start": "2019-01-11",
"date_stop": "2019-05-06"
}
},
"id": "000"
}
https://developers.facebook.com/docs/marketing-api/insights/parameters#param
Accessing un-sampled reports requires the Report Id as input.
How do I list ids of all the un-sampled reports?
Doing an Unsampledreport.list will return a list of the unsampled reports.
GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/unsampledReports
{
"kind": "analytics#unsampledReports",
"username": string,
"totalResults": integer,
"startIndex": integer,
"itemsPerPage": integer,
"previousLink": string,
"nextLink": string,
"items": [
management.unsampledReports Resource
]
}
Context:
I'm building a website using Symfony2 (php) and I have already implemented a social(google) login function (through HWIOAuthBundle) that allows users to:
- register a new account using their own google account
- link a google account to an existing non-social account
As a result, in my database the users table already has a google_id field.
What I want to do:
Users must be able to submit youtube links of their own videos. These links will be saved in the database BUT first I need to verify that the video BELONGS(IS OWNED) to the user that is submitting the link. In other words: users CAN NOT submit videos uploaded by someone else.
I plan on using the Youtube API (php) that you can find on the google developers website.
Question(s):
How can I verify this condition? Can I use the Google Id that I already have in my users table? Or do I need to create a new youtube_id field because the id is different from the google_id? What api function/method should I call to verify the video ownership?
Ideas?
Try to check them by v3/videos - https://developers.google.com/youtube/v3/docs/videos/list
if you use "part=snippet"
you will see channel info in items->snippet->channelId and items->snippet->channelTitle
For example for https://www.youtube.com/watch?v=YVe2THgSDxc load
https://www.googleapis.com/youtube/v3/videos?id=YVe2THgSDxc&part=snippet&key=[YOUR_API_KEY]
You will get
{
"kind": "youtube#videoListResponse",
"etag": "*******",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "*******",
"id": "YVe2THgSDxc",
"snippet": {
"publishedAt": "2018-01-22T15:47:46.000Z",
"channelId": "UCiP6wD_tYlYLYh3agzbByWQ",
"title": "30 Minute HIIT Cardio*******",
"description": "Full info for thi*******.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/YVe2THgSDxc/default.jpg",
"width": 120,
"height": 90
},
*******
},
"channelTitle": "FitnessBlender",
"tags": [
"fitness blender",
"fitness",
"blender",
"workout",
"workout videos",
"hiit workout",
"cardio workout",
"hiit cardio",
"cardio at home",
"hiit at home",
"at home hiit",
"at home workouts",
"free workout videos",
"hiit cardio workout",
"strength",
"strength training",
"strength training workout",
"dumbbell workout",
"at home strength training",
"strength and hiit",
"hiit and strength",
"lower body workout",
"butt workout",
"thigh workout",
"butt and thigh workout",
"fat burning workout",
"muscle building workout"
],
"categoryId": "26",
"liveBroadcastContent": "none",
"localized": {
"title": "30 Minute HIIT Ca*******",
"description": "Full info for this *******"
}
}
}
]
}
So if you have users's channelID or channelName you can compare it with video's channelID or channelName.
If you have user's name but haven't his channel list you can get it by v3/channels
For example this gets channel list for user "popsugartvfit"
https://www.googleapis.com/youtube/v3/channels?&part=contentDetails&forUsername=popsugartvfit&key=[YOUR_API_KEY]
You will get
{
"kind": "youtube#channelListResponse",
"etag": "*****",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "*******",
"id": "UCBINFWq52ShSgUFEoynfSwg",
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUBINFWq52ShSgUFEoynfSwg",
"watchHistory": "HL",
"watchLater": "WL"
}
}
}
]
}
And use if for validation
How can we identity the date on which someone liked my page.
is there any way where we can identify the date on which someone liked my page ?
No. You can't even get a list of people that like your page, so you can't get a date they liked it. The only information you can get is how many people like it.
You can view a chart of how many people liked your page over time at Facebook Insights.
Well no, You can make a graph call to the statuses and feeds of a user with valid access_token to get the id and name of the people who liked the post.. The timestamp can be found for the comments though ..
{
"id": "257821xxxxxxx",
"from": {
"name": "Maxxxxxx",
"id": "100xxxxxx"
},
"message": "incredible ..",
"updated_time": "2011-09-15T11:21:15+0000",
"likes": {
"data": [
{
"id": "6xxxxxx6",
"name": "Axxxxxxxxxa"
}
]
},
"comments": {
"data": [
{
"id": "257xxxxxxxxxxxx904",
"from": {
"name": "Maxxxxxxxxxxal",
"id": "1xxxxxxxxxxxxxx"
},
"message": "htxxxxxxxxxxxxxxxxxxxxxxxxxx",
"can_remove": true,
"created_time": "2011-09-15T11:22:06+0000"
}
]
}
}