<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "HIDDEN FOR STACK ASSIST",
'oauth_access_token_secret' => "HIDDEN FOR STACK ASSIST",
'consumer_key' => "HIDDEN FOR STACK ASSIST",
'consumer_secret' => "HIDDEN FOR STACK ASSIST"
);
// Your specific requirements
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?q=#trekconspringfield&result_type=recent';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$response = json_decode($response, true); //tried with and without true - throws class error without it.
foreach($response as $tweet)
{
$url = $tweet['entities']['urls'];
$hashtag = $tweet['entities']['hashtags'];
$text = $tweet['text'];
echo "$url <br />";
echo "$hashtag <br />";
echo "$text <br />";
echo "<br /><br />";
}
echo "<pre>". var_dump($response) ."</pre>";
?>
当我运行此代码时,它会在响应中获取数据,但是当我尝试解析它以将数据分成有用的东西时,它显示为空白。我在这里浏览了几乎所有 PHP JSON 和 Twitter 标签答案,并尝试了几乎所有这些答案,但都没有成功。发送到 Code God's 寻求答案。谢谢你。
当前上传到的页面... http://trekconspringfield.com/twitter.php