I cannot get the foreach loop to display any data from the twitter api
Please see code below. However, it does display data on print_r array.
thank you for your time in advance
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "*******",
'oauth_access_token_secret' => "*******",
'consumer_key' => "********",
'consumer_secret' => "*******"
);
/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=love+you&count=20';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there
was a problem.</h3><p>Twitter returned the following error
message:</p><p><em>".$string[errors][0]["message"]."
</em></p>";exit();}
foreach($string as $tweets) {
echo $tweets['name'] . '<br />';
}
cannot get the foreach loop to display any data from the twitter api
Please see code below. However, it does display data on print_r array.
thank you for your time in advance
/**here is the a sample of the array data but when the foreach loop is
added the screen is blank no error is dispayed no data is displayed**/
Array
(
[statuses] => Array
(
[0] => Array
(
[metadata] => Array
(
[iso_language_code] => en
[result_type] => recent
)
[created_at] => Thu Mar 05 23:16:36 +0000 2015
[id] => 573623174589472768
[id_str] => 573623174589472768
[text] => @TheVampsband #TheVampsVIP Please choose me and
@Charlotte_94x to win