mavera2 Posted September 23, 2011 Share Posted September 23, 2011 By using twitter api, i'm trying to get latest trends. I need to take trends name and creation time of the list. Can you help me to obtain the values from the array? Thank you This code doesn't work. <?php $jsonurl = 'http://api.twitter.com/1/trends/44418.json'; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json); foreach ( $json_output->trends as $trend ) { echo "{$trend->name}\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/247692-twitter-api-parsing-with-php-help/ Share on other sites More sharing options...
WebStyles Posted September 23, 2011 Share Posted September 23, 2011 try this: <?php $jsonurl = 'http://api.twitter.com/1/trends/44418.json'; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json,true); $trends = $json_output[0]['trends']; foreach ( $trends as $trend ){ echo $trend['name']."<br />"; } ?> *whenever you're in doubt with arrays, it's best to use: echo '<pre>'; print_r($array); to look at the whole structure of the returned/converted array. EDIT: Sorry, forgot the creation date/time, it will be in: echo $json_output[0]['as_of']; Link to comment https://forums.phpfreaks.com/topic/247692-twitter-api-parsing-with-php-help/#findComment-1272001 Share on other sites More sharing options...
mavera2 Posted September 23, 2011 Author Share Posted September 23, 2011 try this: <?php $jsonurl = 'http://api.twitter.com/1/trends/44418.json'; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json,true); $trends = $json_output[0]['trends']; foreach ( $trends as $trend ){ echo $trend['name']."<br />"; } ?> *whenever you're in doubt with arrays, it's best to use: echo '<pre>'; print_r($array); to look at the whole structure of the returned/converted array. EDIT: Sorry, forgot the creation date/time, it will be in: echo $json_output[0]['as_of']; That really helped me much ) Thank you for your help and suggestions. Link to comment https://forums.phpfreaks.com/topic/247692-twitter-api-parsing-with-php-help/#findComment-1272003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.