Подпишитесь с помощью Superfeedr PubSubHubbub, вызвав ошибку hub.topic not found

Я хочу интегрировать Superfeedr API с помощью PubSubHubbub в PHP. Я следую этому, и мой код:

<?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 работает нормально. Но я не знаю, почему я получаю эту ошибку на своем локальном компьютере. Если у кого-то есть опыт с такой же проблемой, пожалуйста, помогите мне. Спасибо.


person nitin7805    schedule 24.08.2016    source источник


Ответы (1)


Вы используете странный URL-адрес концентратора. Вы должны использовать HTTPS://push.superfeedr.com в последнем параметре вашего конструктора класса.

person Community    schedule 24.08.2016
comment
Привет Жульен, Спасибо за ваш ответ. Я меняю URL, как вы советовали. Но теперь я получаю HTTP/1.1 401 Unauthorized Unauthorized. Нужно ли проходить аутентификацию перед подпиской? Я следую documentation.superfeedr.com/ для проверки подлинности HTTP. Я также сгенерировал токен и вставил его в свой код, как вы видите, hub.verify_token = 26550615cbbed86df28847cec06d3769. Должен ли я сделать что-то другое для аутентификации? - person nitin7805; 25.08.2016
comment
это сработало, на самом деле проблема с аутентификацией была связана с curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME:PASSWORD'); Здесь нам нужно установить фактическое имя пользователя и пароль учетной записи superfeedr.com. Еще раз спасибо @Julien. - person nitin7805; 25.08.2016