I am running a php website and would like to pull in the most recent tweet from my companies twitter feed. Below is the code that I have, however it is currently not working. What have I done wrong? Do I need to change any setting in Twitter to get this method to work?
$responseJson = file_get_contents('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=take_me_fishing&include_rts=1&count=1');
if ($responseJson)
{
$response = json_decode($responseJson);
$status = $response->text;
}
The value of
$responseis an array of objects. Since you only retrieved the last one, you’ll want to access the first item within this array. To access the “text” property of the first element, change your code as follows:Note that when you
print_r($response)you’ll see the following structure: