如何通过 PHP 使用 Superfeedr

发布于 2024-09-27 23:56:34 字数 210 浏览 6 评论 0原文

我正在开发一个解析大量 RSS 提要的项目,我刚刚发现 Superfeedr 在如何使用其 PubSubHubbub PHP API。

请问有人可以给我一个很好的教程或示例如何使用它来订阅任何提要吗?

谢谢你,

I'm working on a project that parse a lot of RSS feeds, and I just discover Superfeedr it has a poor documentation in how to use their PubSubHubbub API with PHP.

Please can anyone give me a good tutorial or an example how to use it to subscribe to any feed?

Thank you,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鸢与 2024-10-04 23:56:34
$x=json_decode(file_get_contents("php://input")); //for recieving new data.
$x=json_decode(file_get_contents("php://input")); //for recieving new data.
水波映月 2024-10-04 23:56:34

Superfeedr的API实际上是PubSubHubbub协议,所以我想第一步是找到实现PubSubHubbub的好方法。这里有一些链接,像这个,或这个

Superfeedr's API is actually the PubSubHubbub protocol, so I guess the first step would be to find the good way to implement PubSubHubbub. There are a few links in here, like this one, or this one.

中二柚 2024-10-04 23:56:34

我以前去过那里。结论如下:
1. 在您的服务器上创建一个 PHP 文件,并将其命名为 endpoint.php,因此文件的 url 应该类似于 http://yoursite.com/endpoint.php

  1. 您应该在 superfeedr.com 创建一个帐户,它应该为您提供用户名/密码
  2. 您的 PHP 文件应该做两件事,订阅/取消订阅提要,在本例中您应该(仅)在文件中写入的所有内容都是 hub_challenge

    (if(isset($_Get["hub_challenge"])){ 
          回声 $_Get["hub_challenge"];
        return;}//确保它只回显 hub_challenge}
    

    成功订阅您的提要后,您应该(自动接收)来自 superfeeder 的新 rss 内容。使用 PHP 你应该收到这样的内容

    $x=json_decode(file_get_contents("php://input"));
        $x 现在是一个新内容的数组。您应该对这个数组执行您想要的操作。
    -- 文件端点应该是这样的
    if(isset($_Get["hub_challenge"])){
       回声 $_Get["hub_challenge"];return;
    }别的{
        $x=json_decode(file_get_contents("php://input"));
        //然后循环它或者你想要的任何东西 
    }
    

添加 rss 链接的方式非常简单,只需在屏幕右上角的帐户链接上访问 superfeedr.com,单击它,然后选择仪表板。

单击 xmpp,您将找到所有提要的列表。您还可以添加新提要。

输入 rss 链接 (http://example.com/rss.xml) 和您的回调 (endpoint.php) 文件。类似于 http://yoursite.com/endpoint.php

按照文档中所述,使用 GET 请求进行卷曲调用。

I was there before. Here is the conclusion:
1. create a PHP file on your server and call it for example endpoint.php so the url of your file should be something like http://yoursite.com/endpoint.php

  1. You should create an account at superfeedr.com it should give you user/pass
  2. Your PHP file should do two things, subscribe/unsubscribe feeds and in this case all what you should write (only) in your file is the hub_challenge

    (if(isset($_Get["hub_challenge"])){ 
          echo $_Get["hub_challenge"];
        return;}//to ensure that it only echo the hub_challenge}
    

    After successfully subscribing your feeds you should (automatically recieve) new rss contents from superfeeder. Using PHP you should recieve contents like this

    $x=json_decode(file_get_contents("php://input"));
        $x now is an array of new contents.you should do what ever you want with this array.
    --the file endpoint should be like
    if(isset($_Get["hub_challenge"])){
       echo $_Get["hub_challenge"];return;
    }else{
        $x=json_decode(file_get_contents("php://input"));
        //then loop through it or what ever you want 
    }
    

The way you add rss link is very simple, just visit superfeedr.com on your account link in the top right of the screen click on it then select dashboard.

click xmpp you will find a list of all your feeds.you can also add new feed.

enter the rss link (http://example.com/rss.xml) and your callback (endpoint.php) file.something like http://yoursite.com/endpoint.php

if you want to add it by PHP code (in any php file).make a curl call with GET request as descibed in documentation.

再可℃爱ぅ一点好了 2024-10-04 23:56:34
  //first create file called callback.php
  //in this file write

  if(isset($_Get["hub_challenge"])){
       echo $_Get["hub_challenge"];
       return;
  }
  //which will be used to subscribe new rss feeds

  //second recieve data
  $my_array = json_decode(file_get_contents("php://input"));
  //offcource you will not be able to see that data and to test it do one of the following to test test results
  //1-mail it to your self
  mail("[email protected]","test callback",print_r($my_array,true)); 
  //2-write it to file and make sure that file has 0777 permissions
  file_put_contents("myfile.txt", print_r($my_array,true));

 //third step if you want to manually add rss links by code not with superfeedr console.
 //after inserting rss link to your db you have to send post request to superfeedr like this
 function superfeedr_curl_post($url, array $post = NULL, array $options = array()){
$defaults = array(  
    CURLOPT_POST => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_URL => $url,
    CURLOPT_FRESH_CONNECT => 1,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_FORBID_REUSE => 1,
    CURLOPT_TIMEOUT => 4,
    CURLOPT_POSTFIELDS => http_build_query($post)
);

$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch)){
    trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
 }

 function superfeedr_subscribe_rss($rss_url){
$mypost=array();
$mypost["hub.mode"]="subscribe";
$mypost["hub.verify"]="async";
$mypost["hub.callback"]="http://yoursite.com/yourcallback-file.php";
$mypost["hub.topic"]=$rss_url;
$mypost["superfeedr.digest"]=true;

$result=superfeedr_curl_post("http://myusername:[email protected]/hubbub",$mypost);
return $result;
}

//then simply you can call
superfeedr_subscribe_rss("http://www.aljazeerasport.net/Services/Rss/?PostingId=201191510242078998");
  //first create file called callback.php
  //in this file write

  if(isset($_Get["hub_challenge"])){
       echo $_Get["hub_challenge"];
       return;
  }
  //which will be used to subscribe new rss feeds

  //second recieve data
  $my_array = json_decode(file_get_contents("php://input"));
  //offcource you will not be able to see that data and to test it do one of the following to test test results
  //1-mail it to your self
  mail("[email protected]","test callback",print_r($my_array,true)); 
  //2-write it to file and make sure that file has 0777 permissions
  file_put_contents("myfile.txt", print_r($my_array,true));

 //third step if you want to manually add rss links by code not with superfeedr console.
 //after inserting rss link to your db you have to send post request to superfeedr like this
 function superfeedr_curl_post($url, array $post = NULL, array $options = array()){
$defaults = array(  
    CURLOPT_POST => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_URL => $url,
    CURLOPT_FRESH_CONNECT => 1,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_FORBID_REUSE => 1,
    CURLOPT_TIMEOUT => 4,
    CURLOPT_POSTFIELDS => http_build_query($post)
);

$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch)){
    trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
 }

 function superfeedr_subscribe_rss($rss_url){
$mypost=array();
$mypost["hub.mode"]="subscribe";
$mypost["hub.verify"]="async";
$mypost["hub.callback"]="http://yoursite.com/yourcallback-file.php";
$mypost["hub.topic"]=$rss_url;
$mypost["superfeedr.digest"]=true;

$result=superfeedr_curl_post("http://myusername:[email protected]/hubbub",$mypost);
return $result;
}

//then simply you can call
superfeedr_subscribe_rss("http://www.aljazeerasport.net/Services/Rss/?PostingId=201191510242078998");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文