Twitter bot not showing as retweeted on twitter feed


#1

rather than using the RT prefix to a tweet, Twitter now provides a retweeted sign on retweeted tweets. I would like this to show up on my retweeted tweets on my twitter bot… i.e. the original user information is embedded on the feed in twitter.com/user

this is the code i have so far (using API 1.1):
PHP Code:

    $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); 
    $twitter->host = "http://search.twitter.com/"; 
    $search = $twitter->get('search', array('q' => '-escort -RT -ADRTBot #abudhabi', 'count' => 5)); 
    $twitter->host = "https://api.twitter.com/1.1/"; 
    foreach($search->results as $tweet) { 
        $status = $tweet->text; 
        if(strlen($status) > 140) $status = substr($status, 0, 139); 
        $twitter->post('statuses/retweet/$tweet->id', array('status' => $status)); 
        print "STATUS: $tweet->id $status<br>"; 
        }  

Any ideas would be gratefully received!!


#2
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
    $twitter->host = "http://search.twitter.com/"; 

    $search = $twitter->get('search', array('q' => '-escort -RT -ADRTBot #abudhabi', 'count' => 5)); 

    $twitter->host = "https://api.twitter.com/1.1/"; 

    foreach($search->results as $tweet) { 

        $status = $tweet->text; 

        if(strlen($status) > 140) $status = substr($status, 0, 139); 

        $twitter->post('statuses/retweet/$tweet->id', array('status' => $status)); 

        print "STATUS: $tweet->id $status<br>"; 

        }  

#3

I struggled with a broken phptwitterbot for a Charity Haunted House I work for, I was banging my head against the wall for a day and this is what I I came up with.

Hope this saves others some time!
-G

<?php // abscero.com retweet script for API 1.1 // based on phptwitterbot // Requires: php twitter Oauth library. https://github.com/abraham/twitteroauth just make sure you change v 1 to 1.1 in the oauth

require_once(’./twitteroauth.php’);

// Define your Keys here, get them from dev.twitter.com
define(‘CONSUMER_KEY’, ‘*****’);
define(‘CONSUMER_SECRET’, '
’);
define(‘ACCESS_TOKEN’, ‘***************’);
define(‘ACCESS_TOKEN_SECRET’, ‘************************’);
// The search function care of rizkyocta63
function search(array $query)
{
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
return $toa->get(‘search/tweets’, $query);
}
// By default, we ignore retweets, change SEARCHWORDS to what you want to search for
$query = array( “q” => “-RT SEARCHWORDS”,);
$results = search($query);

foreach ($results->statuses as $result) {
$retweet = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$retweet->host = “https://api.twitter.com/1.1/”;
$status = $result->text;
$tid= $result->id;
//Make Sure its under 140 or trim it.
if(strlen($status) > 140) $status = substr($status, 0, 139);
// Post the retweets to Twitter
$retweet->post(‘statuses/retweet/’.$tid.’’);
// Output the retweets
echo $result->user->screen_name . ": " . $result->text . “\n”;
}
?>


#4

Thanks a lot BloodviewBot, your sample works like a charm, I was also trying to do this since couple of days. So nice of you

I want to ask one thing, how to search twitter handle instead of -RT, or search multiple twitter handles and what are other parameters we can use?

$query = array( "q" => "-RT SEARCHWORDS",);

Also It is possible to save last RTs in some file? so it will not try to Retweet the same? or we can use since_time in search string?