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'];
}
Related
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.
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!
I need fetch instagram posts by tag every n minutes.. I use
https://api.instagram.com/v1/tags/MYTAG/media/recent?access_token=xx.xxxx
ok, but I don't want to get the same posts every time, I want just to fetch only the new posts.. I thought to use a param.. (for example created_time), save it, and to use it like a filter param in the next request, to save the created_time field of the last post.. save it, repeat this.
but API only allow this parameters:
PARAMETERS
COUNT Count of tagged media to return.
MIN_TAG_ID Return media before this min_tag_id.
MAX_TAG_ID Return media after this max_tag_id.
Then I thought using MIN_TAG_ID in the request instead of Created_time, but the TAG_ID is not found in the api's response json ... (I can filter by TAG_ID but TAG_ID not come in the response. Unusual!!)
Any ideas?
In the response it is simply called id not tag_id
I recomend you to use subscriptions. And you will process new posts in real-time.
I'm using the YouTube Search API to grab 5 videos per time under a specific keyword. But I've been trying and trying, but couldent find the parameter for the start index. Does anyone know how to add it, so it gets the next 5 videos etc..?
Current URL I have:
https://www.googleapis.com/youtube/v3/search?part=snippet&q=wiz+khalifa&type=video&key=AIzaSyB9UW36sMDA9rja_J0ynSYVcNY4G25
In the results of your first query, you should get back a nextPageToken field.
When you make the request for the next page, you must send this value as the pageToken.
So you need to add pageToken=XXXXX to your query, where XXXXX is the value you received in nextPageToken.
Hope this helps
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"*.