【问题标题】:twitter bot not showing as retweeted on twitter feedtwitter bot 未在 twitter 提要上显示为已转发
【发布时间】:2013-03-26 17:41:34
【问题描述】:

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

这是我目前的代码(使用 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

【问题讨论】:

    标签: twitter tweets


    【解决方案1】:

    您应该将代码与原始编码器分开。直到 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!";
    

    [/代码]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-16
      • 2022-01-08
      • 1970-01-01
      • 2011-08-25
      • 2023-04-11
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多