Jump to content

Recommended Posts

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;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/195732-twitter-json-search-api/
Share on other sites

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 :(

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.