Welcome Guest, Not a member yet? Register   Sign In
How to retweet with Haughin Library
#1

[eluser]simotho[/eluser]
Hello all.
I'm using Haughin's Library for the Twitter API, but there isn't a way to retweet a tweet. Anyone knows how to do that? Smile

I tried with:


$this->twitter->call('statuses/retweet', array('id' => $id));
But nothing happens
#2

[eluser]jmisavage[/eluser]
Hey I just figured this out. You'll need to modify the Twitter class in order to get it to work. In the $_methods array add a new entry:

Code:
'statuses/retweet' => array('http' => 'post',    'auth' => TRUE),

Then you to modify the call method. You should see an if statement that counts the parts of the method. Retweeting uses 3 parts and that isn't being handled. Right now I've only added a special case for retweet since I don't want to break anything else.

Code:
if ( $this->oauth !== NULL )
{
    $parts = explode('/', $method);
            
    if(preg_match("/retweet/", $method)) {
        $method_string = $http.'_'.$parts[0].ucfirst($parts[1]).($parts[2]);
    }
    else if ( count($parts) > 1 )
    {
        $method_string = $http.'_'.$parts[0].ucfirst($parts[1]);
    }
    else
    {
        $method_string = $http.'_'.$parts[0];
    }
            
    $data = $this->oauth->$method_string($params);
    return $data->_result;
}
#3

[eluser]jmisavage[/eluser]
D'oh. Messed something up. The $_methods array is worthless since the id of the retweet changes so I added the following function into the call method.

Code:
if(preg_match('/retweet/', $method)) {
    $http = "post";
    $auth = TRUE;  
}

and I'm call it using this:

Code:
$this->twitter->call('statuses/retweet/123456789012345');

I guess if I used a property array then I wouldn't need to do that, but I would still have to hack in something to merge the tweet id into the $method_string.




Theme © iAndrew 2016 - Forum software by © MyBB