提取推文和存储

<?php
$mongo = new Mongo();
$db = $mongo->twitter;
$collection = $db->tweets;
$screen_name = "learnmongo";
$twitter = "http://api.twitter.com/1/statuses/user_timeline.json?";
$twitter .= "screen_name=" . $screen_name;
$curl = curl_init($twitter);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$usertimeline = curl_exec($curl);
curl_close($curl);
$usertimeline = json_decode($usertimeline);
foreach ($usertimeline as $id => $item) {
$collection->insert($item);
}

?>

execution of this code gives error message as invalid parameters to foreach().plzz reply and hep me to solve this problem

You are using a deprecated verion of the Twitter API. Version 1.0 no longer works, you need to use version 1.1. You need to use version 1.1 of the call. The API URL has changed from:

http://api.twitter.com/1/statuses/user_timeline.json

to

http://api.twitter.com/1.1/statuses/user_timeline.json

Unfortunately the new 1.1 version requires authentication so your code will still not work until you implement an OAUTH solution for authentication.