Twitter机器人没有在Twitter上显示转发

时间:2013-04-04 14:56:31

标签: twitter tweets

不是使用推特的RT前缀,Twitter现在在转发的推文上提供了一个转推的标志。我希望这能在我的Twitter机器人上显示我转发的推文...即原始用户信息嵌入在twitter.com/user上的Feed中

这是我到目前为止的代码(使用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>";
        }

任何想法都会感激不尽!


以上不起作用......我仍然在努力转发使用新的api 1.1。

以下是我目前修改的代码:

        <?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);

    ?>

但是,它没有发布到Twitter ...我错过了什么?

非常感谢,

[R

1 个答案:

答案 0 :(得分:0)

你应该从原始编码器中单独留下代码。直到2天前,这个机器人实际上工作了但是由于API 1.1上的Twitter更新,机器人已经停止运行,我认为这取决于search.twitter.com的属性但是要回答你的问题

[代码]

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!";

[/代码]