i trying to know if my channel is streaming on youtube. I'm using the youtube api v3 with the php library.
I'm able to get the last broadcasts with liveBroadcasts.list but when I start streaming with OBS I put the parameters broadcastStatus = active and nothing is returned.
I also tried with liveStreams.list but I still get nothing. I don't know what I'm doing wrong, can someone explain me please ? :D
Try to use the search.list, Here you can set the optional parameters to search what you need. Like the channelId, eventType that you can set to live to include active broadcast, and type parameter that restricts a search query to only retrieve a particular type of resource.
Read the other parameters to know more about its purpose and description.
For more information you can also check this SO question:
Using YouTube API v3 to tell if a channel has a live stream
How to check if YouTube channel is streaming live
The request url is :
GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2Cstatus&mine=true&broadcastStatus=active&key={YOUR_API_KEY}
you should receive :
{"status":{ "lifeCycleStatus":"live"}}
You can use the search API - something like this:
https://www.googleapis.com/youtube/v3/search?part=id&channelId={CHANNEL_ID_YOU_WANT_TO_QUERY}&type=video&key={YOUR_API_KEY}&eventType=live
However, this might take 3-5 minutes before it shows the Video ID of broadcast video after the broadcast has started. This has been discussed in another StackOverflow Question: Using YouTube API v3 to tell if a channel has a live stream
Related
I am using below url to get Dailymotion trending videos, If i open the url in browser, it gives the correct data, but while scrapping the api using php, it gives me different results..
https://api.dailymotion.com/videos?fields=title&flags=no_live,no_premium&private=0&sort=trending&limit=20&country=in
With provided URL, it seems that DailyMotion API ignore the country parameter.
Fast reading API DOC, I understand that country parameter is used to set locale or as returned value.
To obtain language-filtered results, you can use language:
https://api.dailymotion.com/videos?fields=title&flags=no_live,no_premium&private=0&sort=trending&limit=20&language=in
This works for me.
Is there a possible way where I can retrieve a list (with thumbnails) of my latest videos from youtube, store the embed code in a database using a cron job so I can show the video on a separate page instead of leading the users to youtube to view the videos? (all in php)
you can try to have a look at this page: https://developers.google.com/youtube/v3/
Google writes that:
You can use the API to fetch search results and to retrieve, insert, update, and delete resources like videos or playlists.
I saw thath PHP API are still in beta version but you can try it out. You must register your application to obtain credential to use API. At developers.google there is a lot of documentation and some examples (https://developers.google.com/youtube/v3/code_samples/php#retrieve_my_uploads)
Using API you don't need to retrieve code and store it into database, you can just show videos directly in your web application. I hope this is what you was looking for let me know if it helps!
Luca
I've to get 3 simple information from a youtube channel given the channel url.
Channel url(example): http://www.youtube.com/user/autocar
Needed info: Total videos, subscribers and total views.
I thought that those information should be simple to retrieve thanks to the API. Instead I'm going crazy trying to understand the Google Data documentation.
I'm working with PHP, so I suppose that I could use the php google client. But on the other side I'm pretty sure that to retrieve those simple information I can avoid to use the full library... anyway, someone knows how to get those data?
First, you need to find the channel id, some URLs come with channel id, some with username.
Great documentation here.
Basically, if it's a
Channel id, you already have it.
Username, channels.list(part="id", forUsername="username")
Once you have the channel id, you'll do a channel->list request to get all these details.
Response will have all the details.
Give it a try with API explorer with a channel id or username.
PHP Samples to get you started fast.
One way to get all the things you have requested is to search for channel
For instance
$channel_query = "channel_name";
$yt_url = "https://gdata.youtube.com/feeds/api/channels?q=".$channel_query."&alt=json&v=2";
$data = file_get_contents($yt_url);
echo "<pre>"; print_r(json_decode($data)); echo "</pre>";
After you get the feed, you would need to loop through the channel entries and match your channel. Best way of doing that is using your channel ID.
I've been reading youtube API in orde to find how could I retrieve videos and relavant data about them using a certain query.
I've found this page - https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters
where there is an example of: https://gdata.youtube.com/feeds/api/videos?q=surfing&caption&v=2
My question is where should I use my API key ? I don't see any section for this in the query above.
Thanks.
For the v2 API, you only need your API key if you're uploading video.
I am looking to find a way to work with a particular channel on youtube
I want to be able to receive a list of videos in that particular channel in xml format
also would like to be able to receive the latest video or couple of videos
I searched through the youtube API but didn't find exactly what I need.
Found the solution
http://gdata.youtube.com/feeds/api/users/[Channel or User]/uploads
you receive a XML with 25 newest videos along with all their information
also all the attributes and more documentation can be found here
[http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html#Retrieving_and_searching_for_videos][1]