Page 1 of 1

PHP XML DOM twitter feed

Posted: Wed Jul 07, 2010 9:05 am
by ew123
I'm trying to list my twitter statuses on a page of my website. I'm using the rss feed. I've had problems using PHP XML DOM before and I tried the fixes to my codes from a precious topic, but it still isn't working.

This code:

Code: Select all

<?php

$xmlDocOne = new DOMDocument();
$xmlDocOne->load("http://twitter.com/statuses/user_timeline/88436402.rss");

//get and output "<item>" elements
$xOne=$xmlDocOne->getElementsByTagName('item');
for ($iOne=0; $iOne<2; $iOne++)
  {
  $item_titleOne=$xOne->item($iOne)->getElementsByTagName('title')
  ->item(0)->childNodes->item(0)->nodeValue;
  $item_linkOne=$xOne->item($iOne)->getElementsByTagName('link')
  ->item(0)->childNodes->item(0)->nodeValue;
  $item_descOne=$xOne->item($iOne)->getElementsByTagName('description')
  ->item(0)->childNodes->item(0)->nodeValue;

  echo ("<li>" . $item_titleOne . "</li>");
  }

?>
Produces this error:
Fatal error: Call to a member function getElementsByTagName() on a non-object in /www/sites/7e1/c10/www.georgewright.me.uk/web/twitterfeed.php on line 10

Does anybody know why and how to fix it?

Thanks

Re: PHP XML DOM twitter feed

Posted: Wed Jul 07, 2010 9:20 am
by AbraCadaver

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
You'll probably get errors about URL file access disabled. This is a php.ini directive: allow_url_fopen

Re: PHP XML DOM twitter feed

Posted: Thu Jul 08, 2010 8:33 am
by ew123
I don't have access to the php.ini file

Re: PHP XML DOM twitter feed

Posted: Thu Jul 08, 2010 10:16 am
by AbraCadaver
ew123 wrote:I don't have access to the php.ini file
Then you are out of luck. Ask your host to enable it or change hosts. You may be able to use cURL if it is available and fetch the XML.