0
votes

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):

    $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!!


The above doesn't work... and i'm still struggling to retweet using the new api 1.1.

Here is the revised code i have so far:

        <?php
    require_once('twitteroauth/twitteroauth.php');

    define('CONSUMER_KEY', 'xxxxx');
    define('CONSUMER_SECRET', 'xxxxx');
    define('ACCESS_TOKEN', 'xxxxx');
    define('ACCESS_TOKEN_SECRET', 'xxxxx');

    $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);

    $tweets = $twitter->get("https://api.twitter.com/1.1/search/tweets.json?q=-escort%20-RT%20-ADRTBot%20abudhabi&count=5");
    $twitter->host = "https://api.twitter.com/1.1/";
    foreach($tweets as $tweet) {
    foreach($tweet as $chirp) {
        $id = $chirp->id_str;
//testing that data coming through... and it is
        echo "<br>THIS IS THE ID: $id<br>";
        echo "statuses/retweet/$id.json<br>";
        echo "$chirp->text<br>";

        $twitter->post('https://api.twitter.com/1.1/statuses/retweet/$id.json');
    }
    }
    echo json_encode($tweets);

    ?>

However, it is not posting to twitter... what am i missing?

Many thanks,

R

1

1 Answers

0
votes

you should have left the code alone from the original coder. Up until 2 days ago this bot actually worked but due to twitter updates on API 1.1 the bot has stopped functioning and I think it's down to the properties of search.twitter.com though to answer your question

[code]

require_once('twitteroauth.php');

define('CONSUMER_KEY', '\\');
define('CONSUMER_SECRET', '\\');
define('ACCESS_TOKEN', '\\');
define('ACCESS_TOKEN_SECRET', '\\');


$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$twitter->host = "http://search.twitter.com/";
$search = $twitter->get('search',array('q' => '#abudhabi', 'another hashtag here', 'another keyword here', 'rrp' => 4));


$twitter->host = "https://api.twitter.com/1.1/";
foreach($search->results as $tweet) {
    $status = 'RT @'.$tweet->from_user.' '.$tweet->text;
    if(strlen($status) > 140) $status = substr($status, 0, 139);
    $twitter->post('statuses/update', array('status' => $status));
}

echo "Success! Check your twitter bot for retweets!";

[/code]