the-dream
03-05-2009, 06:51 PM
Hi guys...
I'm in search of help again... basically, what I am trying to do, get a list of 'authors' from a Twitter atom feed in the simplest way possible.
This is what I've done so far...
<?php
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$feedURL = "http://search.twitter.com/search.atom?q=dog";
$ch = curl_init($feedURL);
curl_setopt_array($ch,$options);
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$twitterFeed = $content;
file_put_contents("tweetdata.xml", $twitterFeed);
?>
So basically, it's grabbing the feed:
http://search.twitter.com/search.atom?q=dog
And putting all of the data into the local file:
tweetdata.xml
Now, I need to figure out how to get the following out of that file...
<entry>
<id>tag:search.twitter.com,2005:1284428632</id>
<published>2009-03-05T18:09:46Z</published>
<link type="text/html" rel="alternate" href="http://twitter.com/Unclefishbits/statuses/1284428632"/>
<title>my dog carries his food into our living room & drops it on the floor in various patterns. I am convinced he is communicating with me.</title>
<content type="html">my <b>dog</b> carries his food into our living room &amp; drops it on the floor in various patterns. I am convinced he is communicating with me.</content>
<updated>2009-03-05T18:09:46Z</updated>
<link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/57614586/TUNATO_normal.jpg"/>
<twitter:source><a href="http://www.twhirl.org/">twhirl</a></twitter:source>
<author>
<name>Unclefishbits (Fishbits)</name>
<uri>http://twitter.com/Unclefishbits</uri>
</author>
</entry>
The bit I need to try and parse out is in bold... I have no idea how to do this, and have been trying for hours!
Please help!
Thanks!
I'm in search of help again... basically, what I am trying to do, get a list of 'authors' from a Twitter atom feed in the simplest way possible.
This is what I've done so far...
<?php
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$feedURL = "http://search.twitter.com/search.atom?q=dog";
$ch = curl_init($feedURL);
curl_setopt_array($ch,$options);
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$twitterFeed = $content;
file_put_contents("tweetdata.xml", $twitterFeed);
?>
So basically, it's grabbing the feed:
http://search.twitter.com/search.atom?q=dog
And putting all of the data into the local file:
tweetdata.xml
Now, I need to figure out how to get the following out of that file...
<entry>
<id>tag:search.twitter.com,2005:1284428632</id>
<published>2009-03-05T18:09:46Z</published>
<link type="text/html" rel="alternate" href="http://twitter.com/Unclefishbits/statuses/1284428632"/>
<title>my dog carries his food into our living room & drops it on the floor in various patterns. I am convinced he is communicating with me.</title>
<content type="html">my <b>dog</b> carries his food into our living room &amp; drops it on the floor in various patterns. I am convinced he is communicating with me.</content>
<updated>2009-03-05T18:09:46Z</updated>
<link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/57614586/TUNATO_normal.jpg"/>
<twitter:source><a href="http://www.twhirl.org/">twhirl</a></twitter:source>
<author>
<name>Unclefishbits (Fishbits)</name>
<uri>http://twitter.com/Unclefishbits</uri>
</author>
</entry>
The bit I need to try and parse out is in bold... I have no idea how to do this, and have been trying for hours!
Please help!
Thanks!