Dimitrios Desyllas
Dimitrios Desyllas

Reputation: 10028

Google websub does not notify for a new video once I upload it in my channel despite having verified subscription?

I have a test channel: https://www.youtube.com/channel/UCsLX1fLM9r7yKqa-YuPGcvg And upon video uploading I have set up a websub hook where sends data to a telegram bot:

index.php

file_put_contents(__DIR__.'/debug.php',"<?php die(); /*\n".$_SERVER['REQUEST_METHOD']."\n*/",FILE_APPEND);

// Bootstrap Sentry
require_once "./lib/sentry.php";
\Sentry\captureMessage("Request ".$_SERVER['REQUEST_METHOD'],\Sentry\Severity::info());

// Sentry also requires Settings as well therefore we use require
$settings = require("./config.php");

$traceId = rand();

if(!isset($settings['YT_CHANNEL_ID'])){
  http_response_code(500);
  \Sentry\captureMessage("$traceId : No youtube channel Id has been Configured",\Sentry\Severity::error());
  exit(0);
}

// Hub sends a GET request for subscription Then a post methos is
if($_SERVER['REQUEST_METHOD'] == "GET"){

  if(!isset($_GET['hub_mode']) || $_GET['hub_mode']!=='subscribe'){
    http_response_code(204);
    exit(0);
  }

  if(!isset($_GET['hub_topic'])){
    http_response_code(400);
    \Sentry\captureMessage("$traceId : Topic has not been provided",\Sentry\Severity::error());
    exit(0);
  }

  $expected_topic = "https://www.youtube.com/feeds/videos.xml?channel_id=".$settings['YT_CHANNEL_ID'];
  if($expected_topic!=trim($_GET['hub_topic'])){
    http_response_code(403);
    \Sentry\captureMessage("$traceId : Googlwe websub provided wrong channel id",\Sentry\Severity::error());
    exit(0);
  }

  if(!isset($_GET['hub_challenge'])){
    http_response_code(400);
    exit(0);
  }

  http_response_code(200);
  header("Content-Type: text/plain");
  echo $_GET['hub_challenge'];
  \Sentry\captureMessage("Hub Is Subscribed",\Sentry\Severity::info());
  exit(0);
}

// Post handling begins here

$string = file_get_contents('php://input');
\Sentry\captureMessage("BODY:\n".$string,\Sentry\Severity::info());
file_put_contents(__DIR__.'/debug.php',PHP_EOL."/*".$string."*/",FILE_APPEND);


require_once "./lib/requestHandler.php";

if(empty($string)){
  http_response_code(400);
  \Sentry\captureMessage("$traceId : Input is empty",\Sentry\Severity::error());
  exit(0);
}


try{
  $ytInfo = parseRequest($string);

  if($ytInfo->channelId != $settings['YT_CHANNEL_ID']){
    // Despite input is valid we no need to send message for a channel that we have not confirued to do so.
    http_response_code(204);
    \Sentry\captureMessage("Channel Missmatch Skipping",\Sentry\Severity::info());
    exit(0);
  }

} catch(\InvalidArgumentException $e){
  http_response_code(400);
  \Sentry\captureException($e);
  exit(0);
}

require_once "./lib/bot_actions.php";

try{
  sendMessageToChannel($settings['TELEGRAM_CHANNEL_ID'],$settings['BOT_TOKEN'],$ytInfo->videoUrl,$ytInfo->videoTitle);
  http_response_code(204);
}catch(\Exception $e){
  \Sentry\captureException($e);
  http_response_code(500);
}

But once I upload my video into my channel it seems that websub does not call the script I developed despite being verified:

enter image description here

Is that a known issue and how did you fix that?


In order to find the issue I did simplify the script:

// Hub sends a GET request for subscription Then a post methos is
if($_SERVER['REQUEST_METHOD'] == "GET"){

  if(!isset($_GET['hub_challenge'])){
    http_response_code(400);
    exit(0);
  }

  http_response_code(200);
  header("Content-Type: text/plain");
  echo $_GET['hub_challenge'];
  exit(0);
}

// Post handling begins here

$string = file_get_contents('php://input');
file_put_contents(__DIR__.'/debug.txt',PHP_EOL.$string,FILE_APPEND);

http_response_code(204);

But still no call from pubsubhubhub into the new script. I did make a new subscription for my channel. But debug.txt is not populated.

Upvotes: 0

Views: 71

Answers (0)

Related Questions