What should be written in callback file of Superfeedr?

611 views Asked by At

I need to generate RSS feed and get title and urls of the posts and so on. I decided to use Superfeedr for it. So in this situation, I'm a subscriber in Superfeedr. There is callback (the subscriber URL) field to get data, but I don't know what should be written in callback file. I researched the net for example code, but I found nothing about example code. BTW, I want to do this process in PHP. So if you know what should I need write to this file, please comment.

2

There are 2 answers

5
Julien Genestoux On BEST ANSWER

John, I think you got it... which is good. Now, what to write in your PHP: this callback url (your PHP file) will be called in 2 different cases:

  1. to verify your intent (to confirm that you want to subscribe)
  2. to notify you of new content.

I'm no PHP person, but I'll dscribe the algorithm for you

To differentiate between the two, you just have to look at the type of request. If it's a GET request, then, it's the verification of intent, and if it's a POST request, then it's the notification of new content.

If it's the verification of content, you just have to echo the hub.challenge provided as a GET param (I believe echo $_GET['hub.challenge']; should work). You should also verify that you really want to the subscription, but that the logic of your app and I don't know it (most people just look up the $_GET['hub.topic'] in their database and if it's there, echo the challenge. If not, echo something else.

If it's the notification of new content, it's a bit more complex. You have to access the BODY of the HTTP request (again, not sure how PHP does it, but I'm sure somebody can help), then, parse it to extract the title and urls, and handle them as you would want (most people will save that in their databases).

I hope this helps!

0
rodpal On

I'm using this code in php. Hope it helps someone

<?php
  if(isset($_Get["hub_challenge"])){
   echo $_Get["hub_challenge"];
   return;
}