Jump to content

Twitter XML problem


tommyinnn

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.