首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Zend框架:如何从twitter获取我的状态

Zend框架:如何从twitter获取我的状态
EN

Stack Overflow用户
提问于 2009-12-30 12:23:58
回答 3查看 2.4K关注 0票数 1

我想在我的网站上展示我在twitter上的最后5或10个状态。现在,我正在使用下面的代码来获取我的twitter状态。

代码语言:javascript
运行
复制
public function getOrganizationsTwitterUpdates(){

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

我必须跟踪以上代码的响应。

代码语言:javascript
运行
复制
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 ( ) ) ) ) )

我有两个问题:

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

$firstStatus =“这是我的第一条推特”;$firstStatusTime =“下午4:30 12-12-09";$secondStatus =”这是我的第二条推特“;$secondStatusTime =”9:30 my 12-12-09";

Q2。我可以获得我的所有状态没有我的密码(我们可以看到任何人的状态在网上)。我不想使用RSS。

EN

Stack Overflow用户

发布于 2009-12-30 12:45:08

我已经将字符串转换为SimpleXML对象/数组,如

$array=(阵列)simplexml_load_string($stroq);

我不知道在这种情况下这对你是否有效。这是为了从我从API获得的XML字符串中获取一个数组。说到这一点,是否可以将Twitter提要作为json并在其上使用json_decode?这将比使用XML容易得多。

不管怎样,看起来你的推特的路径是

代码语言:javascript
运行
复制
$firstStatusTime=$response->status[1]->created_at
$firstStatus=$response->status[1]->text

但是,如果没有物体本身或更清晰的打印,就很难说了。

对Q2来说,是的,你可以在没有密码的情况下从推特上获取任何人的消息(如果没有保护的话)。

票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1979933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档