Faisal Shaikh
Faisal Shaikh

Reputation: 4157

Push notification for uploading new video in Youtube in Android app

I have integrated YouTube API with my Android app. I am able to fetch all kind of information from API and display it into my app. Currently, I am looking for the solution to show push notification in Android app whenever I uploaded video on youtube.

Is there any API available for this?

Upvotes: 0

Views: 1686

Answers (2)

Tarek Dahab
Tarek Dahab

Reputation: 11

You need a server side to do this, - you can to develop a cron job to run with interval Like 10 minutes - get channel videos based on publishing time

  $minutes= round(abs(time() - strtotime( $video['published'])) / 10,0); 

if minutes less than 10 minutes you can get this video details and push it to your app

I have sample code written in php from 4 years ago

$youtubelib= APPPATH.'include/youtube.php';
include_once($youtubelib);
$channels=$this->channels->getChannelsPush();
foreach ($channels as $key => $value) {
$channel[$key]= new youtube();
$channel[$key]->set_username($value);
$feed[$key]=$channel[$key]->feed();
$vedios[$key]=$feed[$key]['videos'];

foreach ($vedios as $key => $value) {
               foreach ($value as $key => $value2) {
                                $minutes=   round(abs(time() - strtotime($value2['published'])) / 60,0);
                                             // <= 60 last hour    edit it for production
                                          if($minutes <=60)
                                                {
                                                $value2['different_time']=$minutes;
                                                $test[]=$value2;
                                                 }
                                                     }
                                }
echo "No videos published on last hour to push </br>"; 
if(!empty($test))
{
echo "vedios has been pushed </br>";
foreach ($test as $key => $value) {
echo "https://www.youtube.com/watch?v=".$value['id'];
$t=$this->apipush->addtrack($value['title'],$value['id'],1);
exec($this->androidvedioPush($value['title'],$value['id'],$value['cover'][0],$t));
 }  

Upvotes: 1

abielita
abielita

Reputation: 13469

You can check this documentation on how YouTube Data API (v3) supports push notifications via PubSubHubbub.

Notifications are pushed out to subscribers via HTTP webhooks, which is much more efficient than polling-based solutions. With PubSubHubbub, your server finds out about events in near real-time, without having to determine the optimal polling interval or repeatedly fetching data that hasn’t changed.

Your PubSubHubbub callback server receives Atom feed notifications when a channel does any of the following activities:

  • uploads a video
  • updates a video's title
  • updates a video's description

You can find the steps that explains how to subscribe to notifications in the documentation above.

Upvotes: 0

Related Questions