tommyinnn Posted December 26, 2009 Share Posted December 26, 2009 I've managed to phase a few projects in the past, but need some help with my Twitter people search - I've created a test Twitter account since you must supply one to run the search - it's already included in my code below I've managed to get the raw XML data, but can't figure out how to get it to display right You can view the raw XML data using http://api.twitter.com/1/users/search.xml?q=Doug%20Williams - (u/n "tommyphp p/w "theword") - although any Twitter username & password work <?php $username = "tommyphp"; $password = "theword"; $twitterHost = "http://api.twitter.com/1/users/search.xml?q=Doug%20Williams"; $curl; $curl = curl_init(); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_URL, $twitterHost); $result = curl_exec($curl); curl_close($curl); header('Content-Type: application/xml; charset=ISO-8859-1'); print $result; ?> <?php $result = new SimpleXMLElement($xml); foreach($result->users->user as $user) { $name = $user->name; ?> <?php echo $name; ?> <? } ?> Thanks for any help or tips anyone can give Link to comment https://forums.phpfreaks.com/topic/186386-twitter-xml-problem/ Share on other sites More sharing options...
rajivgonsalves Posted December 26, 2009 Share Posted December 26, 2009 try this code <?php $username = "tommyphp"; $password = "theword"; $twitterHost = "http://api.twitter.com/1/users/search.xml?q=Doug%20Williams"; $curl; $curl = curl_init(); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_URL, $twitterHost); $result = curl_exec($curl); curl_close($curl); //header('Content-Type: application/xml; charset=ISO-8859-1'); //print $result; $xml = new SimpleXMLElement($result); foreach($xml->user as $user) { $name = $user->name; echo $name ."<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/186386-twitter-xml-problem/#findComment-984272 Share on other sites More sharing options...
tommyinnn Posted December 26, 2009 Author Share Posted December 26, 2009 WOW, thanks so much - that did the trick!! Link to comment https://forums.phpfreaks.com/topic/186386-twitter-xml-problem/#findComment-984273 Share on other sites More sharing options...
9three Posted December 26, 2009 Share Posted December 26, 2009 If you want to optimize your code a bit you can do $name = ''; foreach($xml->user as $user) { $name .= $user->name.'<br />'; } echo $name; Instead of printing for each iteration you only print once. Link to comment https://forums.phpfreaks.com/topic/186386-twitter-xml-problem/#findComment-984298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.