使用 Superfeedr PubSubHubbub 订阅生成错误 hub.topic 未找到

Posted

技术标签:

【中文标题】使用 Superfeedr PubSubHubbub 订阅生成错误 hub.topic 未找到【英文标题】:Subscribe using Superfeedr PubSubHubbub generating error hub.topic not found 【发布时间】:2016-08-24 14:11:21 【问题描述】:

我想在 php 中使用 PubSubHubbub 集成 Superfeedr API。我正在关注this,我的代码是:

<?php

 require_once('Superfeedr.class.php')
 $superfeedr = new Superfeedr('http://push-pub.appspot.com/feed', 
                            'http://mycallback.tld/push?feed=http%3A%2F%2Fpush-pub.appspot.com%2Ffeed',
                            'http://wallabee.superfeedr.com');

 $superfeedr->verbose = true;
 $superfeedr->subscribe();
?>

而我的 subscribe() 函数是

public function subscribe()

    $this->request('subscribe');


private function request($mode)

    $data = array();
    $data['topic'] = $this->topic;
    $data['callback'] = $this->callback;

    $post_data = array ( 
            "hub.mode" => 'subscribe', 
            "hub.verify" => "sync", 
            "hub.callback" => urlencode($this->callback), 
            "hub.topic" => urlencode($this->topic),
            "hub.verify_token" => "26550615cbbed86df28847cec06d3769",
    ); 
//echo "<pre>"; print_r($post_data); exit;

    // url-ify the data for the POST 
    foreach ($post_data as $key=>$value)  
        $post_data_string .= $key.'='. $value.'&'; 
     
    rtrim($fields_string,'&'); 

    // curl request
    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, $this->hub); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data_string); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
    curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME:PASSWORD');
    $output = curl_exec($ch);


    if ($this->verbose) 
        print('<pre>'); 
        print_r($output); 
        print('</pre>');
       
   

但执行后我收到此错误

HTTP/1.1 422 Unprocessable Entity
X-Powered-By: The force, Luke
Vary: X-HTTP-Method-Override, Accept-Encoding
Content-Type: text/plain; charset=utf-8
X-Superfeedr-Host: supernoder16.superfeedr.com
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Authorization
Content-Length: 97
ETag: W/"61-db6269b5"
Date: Wed, 24 Aug 2016 14:01:47 GMT
Connection: close

Please provide a valid hub.topic (feed) URL that is accepted on this hub. The hub does not match.

从https://superfeedr.com/users/testdata/push_console 请求的相同数据(主题和回调等) 工作正常。但我不知道为什么我在本地收到此错误。如果有人遇到过同样的问题,请帮助我。谢谢。

【问题讨论】:

【参考方案1】:

您正在使用一个奇怪的中心 URL。您应该在类构造函数的最后一个参数中使用HTTPS://push.superfeedr.com

【讨论】:

您好 Julien,感谢您的回复。我按照您的建议更改了网址。但现在我得到 HTTP/1.1 401 Unauthorized Unauthorized。订阅前需要认证吗?我正在关注documentation.superfeedr.com/… 进行 HTTP 身份验证。我还生成了一个令牌并将其放入我的代码中,如您所见“hub.verify_token = 26550615cbbed86df28847cec06d3769”。我应该为身份验证做一些不同的事情吗? 它起作用了,实际上身份验证问题是由于 curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME:PASSWORD');这里我们需要设置superfeedr.com账户的实际用户名和密码。再次感谢@Julien。

以上是关于使用 Superfeedr PubSubHubbub 订阅生成错误 hub.topic 未找到的主要内容,如果未能解决你的问题,请参考以下文章

对使用 Superfeedr 使用 XMPP 或 Pubsubhubbub 订阅和下载 RSS 提要感到困惑

如何将 Superfeedr 提要保存到数据库?

将 Superfeedr 聚合提要检索到节点库

使用 Superfeedr PubSubHubbub 订阅生成错误 hub.topic 未找到

处理来自 superfeedr 的重复通知

Python 和 Visual Studio 需要安装 Node.js 模块(Superfeedr Node.js 包装器)