Zend Framework:如何从 Twitter 获取我的状态 [英] Zend Framework: How to get my statuses from twitter

查看:26
本文介绍了Zend Framework:如何从 Twitter 获取我的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上显示来自 Twitter 的最近 5 或 10 个状态.现在我正在使用以下代码来获取我的 Twitter 状态.

公共函数 getOrganizationsTwitterUpdates(){$twitter = new Zend_Service_Twitter('myusername', 'mypassword');$response = $twitter->status->userTimeline();返回 $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] => 这是我的第二条推文.[来源] => web [截断]=> false [in_reply_to_status_id] => SimpleXMLElement Object () [in_reply_to_user_id] => SimpleXMLElement Object () [收藏夹] => false [in_reply_to_screen_name] => SimpleXMLElement Object () [user] => SimpleXMLElement[id] => 100469557 [name] => naveed [screen_name] => naveedriksof [location] => SimpleXMLElement Object ( ) [描述] => 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] =>2009 年 12 月 30 日星期三 10:59:31 +0000 [favourites_count] =>0 [utc_offset] =>SimpleXMLElement 对象 ( ) [time_zone] =>SimpleXMLElement 对象 () [profile_background_image_url] =>http://s.twimg.com/a/1262113883/images/themes/theme1/bg.png [profile_background_tile] =>false [通知] =>false [geo_enabled] =>假 [已验证] =>假[以下] =>false [statuses_count] =>2) [地理] =>SimpleXMLElement 对象 ( ) ) [1] =>SimpleXMLElement 对象 ( [created_at] => Wed Dec 30 11:01:43 +0000 2009 [id] => 7192966364 [text] => 这是我的第一条推文 [source] => web [截断] =>; false [in_reply_to_status_id] => SimpleXMLElement Object ( ) [in_reply_to_user_id] => SimpleXMLElement Object ( ) [收藏夹] => false [in_reply_to_screen_name] => SimpleXMLElement Object ( ) [user] =>id SimpleXMLElement Object (] => 100469557 [名称] => naveed [screen_name] => naveedriksof [location] => SimpleXMLElement Object ( ) [描述] => 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] =>2009 年 12 月 30 日星期三 10:59:31 +0000 [favourites_count] =>0 [utc_offset] =>SimpleXMLElement 对象 ( ) [time_zone] =>SimpleXMLElement 对象 () [profile_background_image_url] =>http://s.twimg.com/a/1262113883/images/themes/theme1/bg.png [profile_background_tile] =>false [通知] =>false [geo_enabled] =>假 [已验证] =>假[以下] =>false [statuses_count] =>1) [地理] =>SimpleXMLElement 对象 () ) ) )

我有两个问题:

第一季度.如何将上述对象转换为数组.在上面的对象中,我可以看到我的两个状态,但是如何将我的状态存储到这样的变量中.

<块引用>

$firstStatus = "这是我的第一条推文";$firstStatusTime = "4:30PM 12-12-09";$secondStatus = "这是我的第二条推文";$secondStatusTime = "9:30PM 12-12-09";

第 2 季度.我可以在没有密码的情况下获得我的所有状态吗(正如我们可以在网上看到任何人的状态).我不想使用 RSS.

解决方案

您可以通过 Zend_Service_Twitter_Search:

$twitter_search = new Zend_Service_Twitter_Search('json');$response = $twitter_search->search('from:Username');打印_r($响应);

I want to show my last 5 or 10 statuses from twitter on my site. For now I am using following code to get my twitter statuses.

public function getOrganizationsTwitterUpdates(){

     $twitter = new Zend_Service_Twitter('myusername', 'mypassword');
     $response = $twitter->status->userTimeline();
     return $response; 
}

And I have to following response from above code.

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

I have 2 question:

Q1. How to convert above object into array. In above object I can see my two statuses but how can I store my status into variable like this.

$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. Can I get my all statuses without my password (As we can see anyone's status on web). I dont want to use RSS.

解决方案

You can get statuses from an individual user with Zend_Service_Twitter_Search:

$twitter_search = new Zend_Service_Twitter_Search('json');
$response = $twitter_search->search('from:Username');
print_r($response);

这篇关于Zend Framework:如何从 Twitter 获取我的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆