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:
As answer to your first question, you could use following code snippet taken directly from the Zend Framework Wiki:
Now the variables
$date
,$text
and$user
could also be arrays, in which case you could write:I am unable to help you with your second question, simply because I don't have a Twitter account and have no experience working with the Twitter API in general. But it doesn't seem like it, judging from the Zend Framework API class.
I've converted strings into SimpleXML objects/arrays like
$array=(array)simplexml_load_string($stroq);
I don't know if this will work for you in this case. That was for getting an array from an XML string I got from an API. Speaking of which, is it possible to just get the Twitter feed as json and use json_decode on it? That would be a lot easier than working with XML.
Anyway, it looks like the path for your tweets is
But it's hard to tell without the object itself in hand or a more clear printing.
For Q2, yes, you can get anyone's messages from twitter with no password (if they're not protected).