0
我想在PHP中使用PubSubHubbub通訊整合Superfeedr API。我下面this和我的代碼是:訂閱使用hub.topic沒有找到Superfeedr PubSubHubbub通訊發生錯誤
<?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();
?>
我的訂閱()函數是
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 工作正常。但我不知道爲什麼我在本地出現這個錯誤。如果任何人有任何經驗相同的問題,那麼請幫助我。謝謝。
嗨Julien,謝謝你的迴應。按照您的建議更改網址。但是現在我得到HTTP/1.1 401 Unauthorized Unauthorized。訂閱前是否需要進行身份驗證?我正在關注HTTP身份驗證的https://documentation.superfeedr.com/subscribers.html#removingfeedswithpubsubhubbub。我還生成了一個令牌並將其放入我的代碼中,您可以看到「hub.verify_token = 26550615cbbed86df28847cec06d3769」。我應該爲認證做些不同的事情嗎? – nitin7805
它的工作,實際上認證問題是由於 curl_setopt($ ch,CURLOPT_USERPWD,'USERNAME:PASSWORD'); 這裏我們需要設置https://superfeedr.com帳戶的實際用戶名和密碼。再次感謝@Julien。 – nitin7805