手动设置google的pubsubhubbub - 没有验证/ Feed结果失败

时间:2013-09-25 14:41:40

标签: php pubsubhubbub

我尝试了超过10个小时来设置Google的pubsubhubbub feed(手动+ php),但它无法正常工作。这是我到目前为止所做的:

  1. 发布'buystreamme.blogspot.de/feeds/posts/default'

  2. 访问了pubsubhubbub.appspot.com/subscribe

  3. 我的endpoint.php看起来像这样:

     <?php
        if (isset($_GET['hub_challenge'])) {
            file_put_contents('verification.txt',"verified");
            header('HTTP/1.1 204 "No Content"', true, 204);
            echo $_GET['hub_challenge'];
            exit;
        }
        else {
            $xml=file_get_contents("php://input");
            file_put_contents('endpoint.txt',$xml);
        }
     ?>
    

    发生了什么(不是)?

    1. 在订阅后调用endpoint.php并正确创建'verification.txt'。
    2. 然后调用“订阅详细信息”,Feed状态保持“未经验证”。
    3. 然后在我的测试博客中创建一个新帖子,不调用回调文件'endpoint.php'(不创建输出)。
    4. 我做错了什么?

      1. Feed是测试Feed,没有订阅者。
      2. 主持人是one.com,有什么阻止通话吗?
      3. 希望有人可以帮助我。我没有看到错误和其他搜索结果没有帮助我:(

        非常感谢,

        托马斯

1 个答案:

答案 0 :(得分:2)

9小时后我找到了答案...所以如果有人遇到类似的问题,我想分享我的想法:

阅读完这篇文章之后

https://groups.google.com/d/msg/pubsubhubbub/7RPlYMds4RI/2mIHQTdV3aoJ

很明显,我必须为Lease Seconds输入一些(int)数字并删除所有验证令牌。对于&#34; sync&#34;也是错误的返回HTTP代码409因为验证类型现在已清除为&#34;同步&#34;已过期。

总而言之,我认为https://pubsubhubbub.appspot.com/subscribe已经过时了。

我的php解决方案:

<?
$secret = hash('sha1', uniqid(rand(), true));
$post_fields = array(
    'hub.callback' => 'some_php_callback_file_on_your_webspace',
    'hub.mode' => 'subscribe',
    'hub.topic' => 'your_feed', // must be equal to "self" href in feed!
    'hub.verify' => 'async',
    'hub.lease_seconds' => '300', //5 minutes subscription, than feed expires
    'hub.secret' => $secret
);

$request = curl_init('https://pubsubhubbub.appspot.com/'); // the hub
curl_setopt($request, CURLOPT_POST, TRUE);
curl_setopt($request, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt( $request, CURLOPT_VERBOSE, 1 );
curl_exec($request);
$code = curl_getinfo($request, CURLINFO_HTTP_CODE);
print_r( $code );
if (in_array($code, array(202, 204))) {
  print_r("Positive response - request ($code). - secret: $secret");
}
else {
  print_r("Error issuing - request - ($code).");
}
curl_close($request);
?>

和我的callback.php文件:

if (isset($_GET['hub_challenge'])) {
    print $_GET['hub_challenge'];
}
else {
    $xml=file_get_contents("php://input");
    file_put_contents('endpoint.txt',$xml);
}

当然不是最终解决方案,但我对2天后的初稿感到满意:)

相关问题