I’m basically trying to get the last tweet on my Twitter page and echo it out, came across this code which ostensibly should do what I want but it gives me an error:
$user = 'TwitterUserName';
$pass = 'password';
$tweet = curl_init("https://twitter.com/statuses/user_timeline.xml");
curl_setopt($tweet, CURLOPT_USERPWD, $user.':'.$pass);
curl_setopt($tweet, CURLOPT_RETURNTRANSFER,1);
$out = curl_exec($tweet);
$out = new SimpleXMLElement($out);
echo $out->status[0]->text;
Error:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in H:\xampp\htdocs\tests\twit.php:13 Stack trace: #0 H:\xampp\htdocs\tests\twit.php(13): SimpleXMLElement->__construct('') #1 {main} thrown in H:\xampp\htdocs\tests\twit.php on line 13
Any ideas on what’s causing the error? Or any suggestions for a better way of doing this?
Thanks.
The XML string that is being returned is invalid. Verify that the fetched string is actually XML (and valid!).