我想在我的网站上显示来自twitter的最近5或10个状态。现在我正在使用以下代码来获取我的twitter状态。Zend Framework:如何从twitter获取我的状态
public function getOrganizationsTwitterUpdates(){
$twitter = new Zend_Service_Twitter('myusername', 'mypassword');
$response = $twitter->status->userTimeline();
return $response;
}
而且我必须按照上面的代码进行响应。
Zend_Rest_Client_Result Object ([_sxml:protected] => SimpleXMLElement Object ([@attributes] => Array ([type] => array) [status] => Array ([0] => SimpleXMLElement Object ([created_at] => Wed Dec 30 11:02:13 +0000 2009 [id] => 7192975030 [text] => This is my 2nd tweet. [source] => web [truncated] => false [in_reply_to_status_id] => SimpleXMLElement Object () [in_reply_to_user_id] => SimpleXMLElement Object () [favorited] => false [in_reply_to_screen_name] => SimpleXMLElement Object () [user] => SimpleXMLElement Object ([id] => 100469557 [name] => naveed [screen_name] => naveedriksof [location] => SimpleXMLElement Object () [description] => SimpleXMLElement Object () [profile_image_url] => http://s.twimg.com/a/1262113883/images/default_profile_6_normal.png [url] => SimpleXMLElement Object () [protected] => false [followers_count] => 0 [profile_background_color] => 9ae4e8 [profile_text_color] => 000000 [profile_link_color] => 0000ff [profile_sidebar_fill_color] => e0ff92 [profile_sidebar_border_color] => 87bc44 [friends_count] => 0 [created_at] => Wed Dec 30 10:59:31 +0000 2009 [favourites_count] => 0 [utc_offset] => SimpleXMLElement Object () [time_zone] => SimpleXMLElement Object () [profile_background_image_url] => http://s.twimg.com/a/1262113883/images/themes/theme1/bg.png [profile_background_tile] => false [notifications] => false [geo_enabled] => false [verified] => false [following] => false [statuses_count] => 2) [geo] => SimpleXMLElement Object ()) [1] => SimpleXMLElement Object ([created_at] => Wed Dec 30 11:01:43 +0000 2009 [id] => 7192966364 [text] => This is my 1st tweet [source] => web [truncated] => false [in_reply_to_status_id] => SimpleXMLElement Object () [in_reply_to_user_id] => SimpleXMLElement Object () [favorited] => false [in_reply_to_screen_name] => SimpleXMLElement Object () [user] => SimpleXMLElement Object ([id] => 100469557 [name] => naveed [screen_name] => naveedriksof [location] => SimpleXMLElement Object () [description] => SimpleXMLElement Object () [profile_image_url] => http://s.twimg.com/a/1262113883/images/default_profile_6_normal.png [url] => SimpleXMLElement Object () [protected] => false [followers_count] => 0 [profile_background_color] => 9ae4e8 [profile_text_color] => 000000 [profile_link_color] => 0000ff [profile_sidebar_fill_color] => e0ff92 [profile_sidebar_border_color] => 87bc44 [friends_count] => 0 [created_at] => Wed Dec 30 10:59:31 +0000 2009 [favourites_count] => 0 [utc_offset] => SimpleXMLElement Object () [time_zone] => SimpleXMLElement Object () [profile_background_image_url] => http://s.twimg.com/a/1262113883/images/themes/theme1/bg.png [profile_background_tile] => false [notifications] => false [geo_enabled] => false [verified] => false [following] => false [statuses_count] => 1) [geo] => SimpleXMLElement Object ()))))
我有2个问题:
Q1。如何将上面的对象转换成数组。在上面的对象中,我可以看到我的两个状态,但是如何将我的状态存储到像这样的变量中。
$firstStatus = "This is my first tweet"; $firstStatusTime = "4:30PM 12-12-09"; $secondStatus = "This is my second tweet"; $secondStatusTime = "9:30PM 12-12-09";
Q2。我可以在没有我的密码的情况下获得我的所有状态(因为我们可以在网上看到任何人的状态)。我不想使用RSS。
这是为我工作。此搜索方法以数组的形式返回结果,我不需要将其转换为数组。我可以通过用户名搜索它,我不需要密码。谢谢。 – NAVEED 2009-12-31 07:08:31
如果有人遇到这个答案,值得注意的是Zend_Service_Twitter_Search使用搜索API,因此只会返回大约一周的推文。如果用户在上周没有发推文,则必须使用zend_service_twitter的用户时间轴方法 – raymosley 2013-04-04 00:52:31