Getting demographics info about youtube channels using youtube api - php

I need to access Youtube channel's demographics data with oauth.
One problem is that Youtube api called insight only provides zipped folders with csv files.
While I can probably download the zip, unzip, access the file, and delete the original once I get the data I need, I was wondering if there is any other way to get youtube channel's demographics data.

I believe that yes, using the new YouTube Analytics API:
https://developers.google.com/youtube/analytics/v1/available_reports
From the doc:
Channel reports
The table below lists the different types of channel reports accessible via the API. To retrieve a channel report, set the ids parameter value to channel==USER_ID, where USER_ID specifies the YouTube user ID of the currently authenticated user.
And I think that is the report you wants:
dimensions: country
metrics: views, comments, favoritesAdded, favoritesRemoved, likes, dislikes, shares, subscribersGained, subscribersLost
filters: video
or this one:
dimensions: ageGroup, gender
metrics: viewerPercentage
filters: country video(,country)
and this example shows how to call the API:
https://developers.google.com/youtube/analytics/v1/sample-application

Related

Choose Channel to Upload a YouTube Video

I have one Youtube Channel with about six subchannels.
How can i define the Channel in the API which i like to Upload a Video to
Something like:
<?php
$snippet->setChannelId("UCYr0l3qoK7cuZynbvDYl7Q");
?>
Check the ChannelSection with the type multipleChannels. As stated in this post, using this method, you were able to:
Pull a list of all channelSections
Find the id of the channelSection whose type is multipleChannels and title is Music Genres (as example).
Using the ID from step 2 you can now Query that specific channelSection
There's no such thing as sub-channels in YouTube. What you probably mean is that you have one Google account that manages multiple individual channels.
When you upload a video, your application will go through the process of obtaining OAuth tokens from the API server. This is where a user action is required: The user gets directed to a webpage on which he can give his permission that the app may access his channel. If a Google account manages multiple channels, the user must select one. The tokens which your app receives as a result of this process are tied to the channel that the user selected and cannot be used to upload to other channels.
These tokens can then be used by your application to perform API requests like uploading videos.

Get last 3 instagram images posted in a place

I've been over the Instagram API for a long time, and couldn't find a way to get the last 3 instagram images posted in a specific place.
For example, a visitor search for "Patrick's Pub". The website will redirect him to the pub's page in my website, and there I will be able to display the last 3 instagram images posted in Patrick's Pub.
Is there any way to display these images? I thought about this URL:
https://api.instagram.com/v1/locations/search?lat=*LAT*&lng=*LNG*&access_token=*THETOKEN*
But there are 2 problems with this:
1. I can't find a way to convert LAT and LNG coordinates to a place (like the Patrick's bar)
2. If need an access token for this URL, it means the user need to log in to his instagram account, and it will not be suitable for the website, for just vieweing a place instagram photos.
Any help will be appreciated.
Its a 3-step approach:
Instagram uses Facebook Places to tag a photo to places, you have to use facebook graph API to search for actual places at a location and get the facebook_places_id:
https://graph.facebook.com/search?q={NAME}&type=place&center={LAT,LNG}&access_token={ACCESS_TOKEN}&expires_in=5184000
You then have to make a Instagram location search API call with the facebook_places_id to get the instagram_location_id:
https://api.instagram.com/v1/locations/search?facebook_places_id={FACEBOOK_PLACES_ID}&access_token={ACCESS-TOKEN}
https://instagram.com/developer/endpoints/locations/#get_locations_search
Use the instagram location id to get the recent photos from the place, using the Instagram location media API:
https://api.instagram.com/v1/locations/{location-id}/media/recent?access_token={ACCESS-TOKEN}
https://instagram.com/developer/endpoints/locations/#get_locations_media_recent
Here is an implementation of this search: http://www.gramfeed.com/instagram/places

Getting YouTube Channel Views

I'm trying to get the channel views of the logged in user, through googles' oauth2. I'm able to get name and email via this url: https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=[GENERATED TOKEN]
Now, I'm having a hard time finding any information about how I would go about getting the users channel views. I know you can get a list of videos and such, but how would I do this?
Is there an equivalent to the link I posted above? :)
You can do a channels->list
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&key={YOUR_API_KEY}
In response contentDetails.relatedPlaylists.watchHistory will have the playlist id of watched videos. You can iterate through that playlist with playlistItems->list.
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+contentDetails&id={PLAYLIST_ID}&key={YOUR_API_KEY}

API Youtube, how to get like and dislikes

On a website, i use API Youtube with ZendGdata for retrieve all video of a user and create webpage with the video and his informations.
Now i need to add a system for like or dislikes video on my website, and i need to retrieve the number of likes and dislikes.
(Yes, there are 2 questions here^^)
So, i retrieve for example title with $videoEntry->getVideoTitle();, number of views with $videoEntry->getVideoViewCount(); but how i can retrieve number of likes/dislikes ?
And how i can vote for a video on my website ?
If you take a look at the videos resource in YouTube 3.0 API, among the values included are:
likeCount
dislikeCount
Full details here: https://developers.google.com/youtube/v3/docs/videos
If you're using the YouTube 2.0 API, then check out the <yt:rating> tag, which contains the following fields:
numLikes
numDislikes
More info here: https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_yt:rating
An update to Cormac answer is that youtube will remove this and you can use it for yourself only.
Note: The statistics.dislikeCount property will be made private as of December 13, 2021. This means that the property will only be included in an API response if the API request was authenticated by the video owner. See the revision history for more information.

php get youtube user subscription channel videos

how can i use php to get youtube user subscription channel videos and display all the channel feeds, i want create a class or function where if i pass a user name the php class would retrieve the latest uploads / activities in the user subscribed channels and display the url plus the title and the image, also i want to be able to pass the title and url to other functions so that i can save it to database. on a another page i found this Pulling in YouTube Videos from Specific Channel but its for only one specific channel.
The relevant requests are for the newsubscriptionvideos feed in the YouTube GData API v2 or activities.list() in the newer YouTube Data API v3.
newsubscriptionvideos might not be natively support in the Zend GData client library (I don't see it mentioned in the developer's guide), so if you go that route, you should probably use alt=jsonc to get back an easy-to-parse JSON feed of the data. E.g, https://gdata.youtube.com/feeds/api/users/jeffposnicktest/newsubscriptionvideos?v=2&alt=jsonc
The alternative is to use v3's PHP client library to call activities.list().

Categories