2013-04-04 63 views
0

而不是將Twitter前綴用於推文,Twitter現在在轉推的推文上提供轉發的標誌。我想這顯示在我的twitter推特上的推特鳴叫...即原始用戶信息是嵌入在飼料twitter.com/userTwitter機器人未在推特上轉發推文

這是我到目前爲止的代碼(使用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

回答

0

你應該從原來的編碼器單獨留在家中的代碼。直到3天前該機器人的實際工作,但由於嘰嘰喳喳的API 1.1機器人的更新已經停止運作,我認爲這是到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!"; 

[/ code]