1

Twitter 已将其脚本基础从 API 1.0 更改为 API 1.1,这让事情变得更加困难。

使用的原始 API 1.0 代码是

[代码]

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' => 'from:eurogamer, OR from:nintendolife, OR from:outsidexbox, OR from:xbox, OR from:OXMUK, OR from:playstationEU, OR from:gamespotuk', '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!";

[/代码]

现在一位用户非常乐于助人并试图破解 API 1.1 配置,但尝试没有成功

API 1.1 代码尝试

[代码]

$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$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!";

[/代码]

所以我试着用我昨晚想出的一个想法来破解它,使用上述代码的基础来征服 API 1.1 系统,但仍然没有成功

[代码]

require_once('twitteroauth.php');

define('CONSUMER_KEY', '//');
define('CONSUMER_SECRET', '//');
define('ACCESS_TOKEN', '//');
define('ACCESS_TOKEN_SECRET', '//');
$notweets = 4;


$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=%40eurogamer%20%40nintendolife%20%40outsidexbox%20%40xbox%20%40OXMUK%20%40playstationEU%20%40gamespotuk."&count=".$notweets);


$twitter->host = "https://api.twitter.com/1.1/";
foreach($tweets 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!";

[/代码]

上面这个特殊的概念确实有一个错误 Parse error: syntax error, unexpected '=' on line 12

有任何想法吗?

4

1 回答 1

0

解析错误源于...

$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=%40eurogamer%20%40nintendolife%20%40outsidexbox%20%40xbox%20%40OXMUK%20%40playstationEU%20%40gamespotuk."&count=".$notweets);

应该是……(注意网址结尾)

$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=%40eurogamer%20%40nintendolife%20%40outsidexbox%20%40xbox%20%40OXMUK%20%40playstationEU%20%40gamespotuk&count=".$notweets);
于 2013-08-07T15:36:50.047 回答