我有一个Twitter机器人,它搜索@mention并根据用户的说法回复用户。
这个工作正常,直到本周,当我开始收到此错误时:
警告:在第14行的/home/reportax/public_html/reportaxi/twitterbot/config.php中为foreach()提供的参数无效
我将代码剥离到最基本的形式,即搜索@mention然后在找到它时发推文,但我仍然收到此错误。有什么想法吗?
正如我之前提到的,直到本周才能正常工作,因此我知道消费者密钥,秘密以及一切正常。
这是代码:
<?php
require_once('twitteroauth.php');
define('CONSUMER_KEY', 'MYKEY');
define('CONSUMER_SECRET', 'MYSECRET');
define('ACCESS_TOKEN', 'MYTOKEN');
define('ACCESS_TOKEN_SECRET', 'MYTOKENSECRET');
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$twitter->host = "http://search.twitter.com/";
$search = $twitter->get('search', array('q' => '@repor_taxi', 'rpp' => 15));
$twitter->host = "https://api.twitter.com/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));
}
?
任何想法?
答案 0 :(得分:0)
我遇到了同样的问题。您需要更新twitter API 1.1的代码。
<?php
require_once('twitteroauth.php');
define('CONSUMER_KEY', 'MYKEY');
define('CONSUMER_SECRET', 'MYSECRET');
define('ACCESS_TOKEN', 'MYTOKEN');
define('ACCESS_TOKEN_SECRET', 'MYTOKENSECRET');
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
/*The search has change a little bit */
/* Remove this 2 lines */
/* $twitter->host = "http://search.twitter.com/"; */
/* $search = $twitter->get('search', array('q' => '@repor_taxi', 'rpp' => 15)); */
/* Put this new line */
$search = $twitter->get("https://api.twitter.com/1.1/search/tweets.json?q=@repor_taxi&count=15");
/* The Search URL is https://api.twitter.com/1.1/search/tweets.json?q= */
/* Everything after is parameter */
/* You can check parameters list here: https://dev.twitter.com/docs/using-search */
/* Twitter host updated too */
$twitter->host = "https://api.twitter.com/1.1/";
foreach($search as $tweet) {
...
?>
我希望这对你有帮助。祝你好运。