原始代码是
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$twitter->host = "http://www.search.twitter.com/";
$search = $twitter->get('search', array('q' => '#hashtag', 'rpp' => 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!";
这最初会搜索某个关键字,并通过该主题标签发布所说的内容。
发布自定义搜索内容$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$twitter->host = "https://twitter.com/search?q=from%3Aeurogamer%2C%20OR%20from%3Anintendolife%2C%20OR%20from%3Aoutsidexbox&src=typd";
$search = $twitter->get('search', array('q' => '', 'rpp' => 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!";
我想我不再需要$ search了,我仍然需要将标准设置为仅发布4,但我该如何解决?
答案 0 :(得分:0)
看了the docs后,我很确定你会这样做:
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// API v1
$twitter->host = "http://search.twitter.com/";
$search = $twitter->get('search', array('q' => 'from:eurogamer OR from:nintendolife OR from:outsidebox', 'rpp' => 4));
/*
// API v1.1 (I think)
$twitter->host = "https://api.twitter.com/1.1/";
$search = $twitter->get('search/tweets',
array('q' => 'from:eurogamer OR from:nintendolife OR from:outsidebox',
'count' => 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!";
(您可能需要urlencode搜索查询字符串,我不知道TwitterOAuth库是否已经为您执行此操作。)