johnslater Posted March 18, 2010 Share Posted March 18, 2010 I'm having some trouble with JSON, i'm new to it and i did my research and thought i had a good understanding of it. I was wrong. Basically the code i have is below, i want to loop out results from the JSON search results from Twitter (in this example the profile picture) but something is wrong and i can find little help online. I hope i'm on the right lines, help would be great. <? $jsonurl = "http://search.twitter.com/search.json?q=twitter"; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json); foreach ($json_output->results[0]->profile_image_url as $trend ) { echo $trend; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/195732-twitter-json-search-api/ Share on other sites More sharing options...
salathe Posted March 18, 2010 Share Posted March 18, 2010 You're almost there, the only problem is your approach to the loop. foreach ($json_output->results as $result) { echo $result->profile_image_url; } Quote Link to comment https://forums.phpfreaks.com/topic/195732-twitter-json-search-api/#findComment-1028293 Share on other sites More sharing options...
johnslater Posted March 18, 2010 Author Share Posted March 18, 2010 You're almost there, the only problem is your approach to the loop. foreach ($json_output->results as $result) { echo $result->profile_image_url; } Warning: Invalid argument supplied for foreach() in /mounted-storage/home114b/sub005/sc49493-NOAI/ifestapp.com/iphone/twitter.php on line 6 still get the same error Quote Link to comment https://forums.phpfreaks.com/topic/195732-twitter-json-search-api/#findComment-1028302 Share on other sites More sharing options...
salathe Posted March 18, 2010 Share Posted March 18, 2010 Take a look at the JSON text, and the object, to see if it looks right: var_dump($json, $json_output) Quote Link to comment https://forums.phpfreaks.com/topic/195732-twitter-json-search-api/#findComment-1028337 Share on other sites More sharing options...
johnslater Posted March 19, 2010 Author Share Posted March 19, 2010 Take a look at the JSON text, and the object, to see if it looks right: var_dump($json, $json_output) For some reason it started working, i'm thinking maybe Twitter was having issues or something. Either way it works now and your method fixed it, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/195732-twitter-json-search-api/#findComment-1028565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.