Youtube API channel search - how to get channel ids by using video ids - api

I am using the Youtube API for a simple search for music in a specific genre. In the results set I get only videos ids and the part with channel ids is empty. Is there any way to generate/get the channel ids from the retrieved videos?
I have tried to look only for channels, but the result set is either completely emtpy or contains 1-2 results.
youtube.search().list(q = query,
part = "id",
#type = 'channel, video',
maxResults = max_results).execute()
I would like to get both videos and channel ids and currently I am receiving only a list of videos that match with the search query.

Yes, just request the 'snippet' part as well. The snippet section contains the channelId of the video.

Related

Get playlist ID from youtube video

Is there any way to find playlist ID of youtube video using API, like through videoID? I looked into /playlistItems endpoint but I'm not sure where I can find the playlist item ID? I've tried to look this over everywhere but I'm at lost.
I looked a bit, and the only method I can find would be limited to your own playlists and playlists on the video's channel (or other channels that you specify):
Get the video ID
If you want to check playlists on the same channel, get the channel ID from the video (see https://developers.google.com/youtube/v3/docs/videos#resource)
Get the playlists you want to check (https://developers.google.com/youtube/v3/docs/playlists/list) - either your own playlists or playlists on
Loop through and get the items on each playlist (https://developers.google.com/youtube/v3/docs/playlistItems/list as you found)
Look for the playlist item that has the same video ID as the one you're examining (https://developers.google.com/youtube/v3/docs/playlistItems#resource)
It's a bit ugly, and limited of course - maybe someone else will share a better method with us.
An alternative could be:
Since you have the video_id, get the title of the video as well.
With the title of the video, use the search:list endpoint for search playlists that matches with the query/criteria - that is, the title of the video.
Loop the results from the search request and use the code I show in my answer for check if the video_id is on the playlist.
Example:
video_id: eJjbnFZ6yA8
title: FULL MATCH - The Rock vs. Mankind – WWE Championship Match: Raw, Jan. 4, 1999
Make search to get playlists that matches the search term: "FULL MATCH - The Rock vs. Mankind – WWE Championship Match: Raw, Jan. 4, 1999"
URL:
https://youtube.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=50&q=FULL%20MATCH%20-%20The%20Rock%20vs.%20Mankind%20%E2%80%93%20WWE%20Championship%20Match%3A%20Raw%2C%20Jan.%204%2C%201999&type=playlist&key=[YOUR_API_KEY]
Try-it here
From the results of the search, get the playlist - for this example I took the first result I got from the search, then, I check if the video_id eJjbnFZ6yA8 is on the playlist PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W
URL:
https://youtube.googleapis.com/youtube/v3/playlistItems?part=id%2Csnippet&playlistId=PLAamU2iv-fSuxZrVqQIBcrrZMTCMbBt2W&videoId=eJjbnFZ6yA8&key=[YOUR_API_KEY]
Try-it here for check the results.
Keep in mind that the search:list endpoint consumes 100 quota points, so, the quota might be drain rather quickly - depending of the intensity of the search.

Vimeo API get multiple videos in one GET request

I'm in a situation where I need to make one GET request to Vimeo and get back info for multiple specific videos. Here is what I have for the query string currently:
https://api.vimeo.com/users/XXXXXXXX/videos?fields=uri,duration,pictures.sizes.link,download&containing_uri=/videos/ID1,/videos/ID2&per_page=2
Unfortunately, this only returns the information for ID2 and the video ID before it in its channel, instead of for both IDs specified. I've also tried appending multiple containing_url fields to no avail. Is there any way to make this happen? I'm using axios in react native if that helps.
Instead of "containing_uri", use "uris" as documented here:
https://developer.vimeo.com/api/common-formats#batch-requests
https://developer.vimeo.com/api/reference/videos#GET/videos
The "containing_uri" parameter will only return the page of the specified uri. The "uris" parameter will return the specified videos/objects. Your request should look like this:
https://api.vimeo.com/users/XXXXXXXX/videos?fields=uri,duration,pictures.sizes.link,download&uris=/videos/ID1,/videos/ID2&per_page=2
I hope this information helps!

How do I get all user photos using the Google Photos API?

I'm using the Picasa Web Albums Data API to access my Google Photos account. My goal is to download all photos between a given start and end time (old vacation pics). This API doesn't support server-side time filtering, so I'm trying to access the meta-data of the most recent 4000 images and filter them by time client-side. I have a working proof of concept, but I can only get the server to return ~900 image references (my Google Photos account easily has 40k total images). Is there some API method I am missing that lets me download the entire "feed" for my user so I can access meta-data on all my photos? Here is what I've tried...
# Tried this first, got ~900 results
pics = gd_client.GetUserFeed(kind='photo', limit=4000).entry
# Tried using the paging parameter start-index, but even if I
# page through until it errors out, there are only ~900 results
pics = gd_client.GetFeed('/data/feed/api/user/default?kind=photo&max-results=100&start-index=500').entry
The APIs for albums do work correctly to list all images - the 'Auto Backup' album (that receives images from Google Photos on Android phones) has 30k images and I can query the meta data of them all.
Unfortunately I cannot put these images into one album and download them that way - user-created albums are limited to 2000 images. (I know there are around 3000 total images from this trip, because I can 'select' them in the web interface and see the total count, but you cannot download that many at once and you cannot add more than 2k to one album.)
After many tries, I think I got it to perfectly work.
What I did is playing with the start-index and max-results simultaneously.
You need to do it as follows (considering keeping max-results value same each request you hit):
start-index = 1 & max-results = Any_Value_You_Want ex: 50
Url request would look like:
/data/feed/api/user/default?kind=photo&max-results=50&start-index=1
start-index = 1 + previous max-results = 51 & max-results = 50
Url request would look like:
/data/feed/api/user/default?kind=photo&max-results=50&start-index=51
start-index = 51 + previous max-results = 101 & max-results = 50
Url request would look like:
/data/feed/api/user/default?kind=photo&max-results=50&start-index=101
And so on, each time you increase the start-index by its original value plus the max-results one in addition to maintaining 50 entries each url request, and it will perfectly work.
Never got API to work as I'd desired, but I was able to "solve" this by downloading the target dates using Google Takeout

youtube API 3 - get all data in single request

I am using YouTube API 3 to fetch video results for which I have to make two http requests which are sequential not parallel.
1- First API call is to get youtube video ids for a search term.
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&q=QUERY_TERM&key={API KEY}
2- From first I am preparing a list of comma separated video IDs (ALL_VIDEO_IDS) and fetching individual video details like duration, viewcount etc.
https://www.googleapis.com/youtube/v3/videos?id=ALL_VIDEO_IDS&part=contentDetails,statistics&key={API KEY}
Actually I want a way so that I can get all these details in one call rather than two. How to achieve this?
Is there a way to achieve it which I don't know or I am missing something?
Here it is, with example of getting video duration,
but do not forget to create your API key at https://console.developers.google.com/project
$vidkey = "cHPMH2sa2Q" ; video key for example
$apikey = "xxxxxxxxxxxxxxxxxxxxx" ;
$dur = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$vidkey&key=$apikey");
$VidDuration =json_decode($dur, true);
foreach ($VidDuration['items'] as $vidTime)
{
$VidDuration= $vidTime['contentDetails']['duration'];
}

Instagram tag search - filter for images and tags after a certain time or id

I am using the Instagram API to fetch a list of photos tagged with a certain hashtag. I've got a real-time subscription set up so it will notify me whenever new photos have been posted. However, I have to fetch the new results myself.
My problem: When I request the list of recently tagged photos, I get a large list and I don't want to process all of the results in the recent list every time I do this. The api docs say I can pass these optional parameters, but they seem counter-intuitive. They seem to be the opposite of what I would expect:
MIN_ID Return media before this min_id.
MAX_ID Return media after this max_id.
If I keep track of the most recent media id I've seen in my recent requests, how do I construct my next request to only return results newer than that id?
I've posted two photos with a test hashtag. When I use the following url (with my real access_token in it), I get back a json response listing both of those photos:
https://api.instagram.com/v1/tags/weirdtest/media/recent?access_token=xxx
The two photos have these ids:
221201236060507271_179249322
221190263853517857_179249322
How do I construct a query that returns only the newer of those two photos?
Tack the most recent ID you've seen on the end, using the MAX_ID request parameter:
https://api.instagram.com/v1/tags/weirdtest/media/recent?access_token=xxx&MAX_ID=221201236060507271_179249322
This should tell Instagram, *"The most recent photo I've seen is 221201236060507271_179249322, return only newer photos"*.