mercredi 31 août 2016

Superfeedr response not working in laravel

I want to retrieve feeds from superfeedr.com using PubSubHubbub api, but my callback response is not working. Here is my code

class Superfeedr
{
    private $topic;
    private $callback;
    private $hub = 'http://ift.tt/H95U5N';
    public $verbose = false;

    function __construct($topic, $callback, $hub='')
    {
        $this->topic = $topic;
        $this->callback = $callback;
        if ($hub) {
            $this->hub = $hub;
        }
    }

    public function request($mode)
    {

        $post_data = array ( 
            'hub.mode'  => 'retrieve',
            'hub.callback'  => urlencode($this->callback),
            'hub.topic' => urlencode($this->topic)
        ); 


        foreach ($post_data as $key=>$value) { 
            $post_data_string .= $key.'='. $value.'&'; 
        } 


        $url =$this->hub .'?'.$post_data_string;

        $ch = curl_init(); 

        curl_setopt($ch, CURLOPT_URL, $url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
        curl_setopt($ch, CURLOPT_USERPWD, 'testdata:1234');
        curl_setopt($ch, CURLOPT_BUFFERSIZE, 4096);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $output = curl_exec($ch);
    }   
}

and my php file is

  #Retrieve.php

  $superfeedr = new Superfeedr('http://ift.tt/1mxyvpX', 
                        'http://ift.tt/2bQUWgt', 
                        'http://ift.tt/KSzPYJ');

  $superfeedr->verbose = true;
  $data = $superfeedr->request('list');

Here I want to inform you that my callback url is one of my laravel action. Which is

public function callback(Request $request)
{
    \Log::info("Testing before callback");
    if(isset($_Get["hub_challenge"])){
       echo $_Get["hub_challenge"];
       return;
    }

    // Just for testing
    \DB::table('test')->insert(['name' => "Test callback data. Please ignore"]);

}

But nothing happens in my log file and database too. Somebody have any idea then please let me know whats wrong here. Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire