My final goal is to set up a Webhook whenever a YouTube user uploads a video. After some research I got to this article.
But when I get to the part https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID
, I got Restricted topic
error when trying the subscribe to the Google/SuperFeedr hubs. I also got my callback URL working.
The topic I want to subscribe to is this: https://www.youtube.com/xml/feeds/videos.xml?channel_id=UC7T8roVtC_3afWKTOGtLlBA
Which shows nothing upon visiting via a browser.
Am I doing something wrong? I've been struggling for a few hours now, any help is appreciated. Thanks!
UPDATE: I found this, but those feeds doesn't have the rel=”hub”
attribute, so probably useless if I want to subscribe it to hub.
subscribe function:
subscribe.php may look like:
after the request is sent, the pusub service will call youtube_subscribe_callback.php to verify the subscription it will use the GET method and it expects to receive an answer which is "hub_challenge". after that if you upload a video to your test channel youtube_subscribe_callback.php will receive POST request with data.
so youtube_subscribe_callback.php (defined in subscribeYoutubeChannel function) may look like:
I wasn't able to subscribe channel by id, but was able to do it by username:
So, you go to this page:
Insert your callback URL, RSS feed from youtube with username, and mode "subscribe".
Don't forget to reply from your callback URL, so it can confirm subscription, in PHP just print:
More details here and here.
The process is usually two steps, first you go to the subscribe page, input your callback server url, topic url (which is basically the feed url for the ytb channel you want to listen to, the other fields are optional), the pub server will verify your subscription with a
GET
request to your callback server, in go it can look like this:Then on every new video (or title, desc of an old video is updated), the pub will submit a
POST
request to your server with anxml
in the body looking similar to this: