PHP XML DOM twitter feed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ew123
Forum Newbie
Posts: 6
Joined: Sat Jun 05, 2010 10:38 am

PHP XML DOM twitter feed

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP XML DOM twitter feed

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ew123
Forum Newbie
Posts: 6
Joined: Sat Jun 05, 2010 10:38 am

Re: PHP XML DOM twitter feed

Post by ew123 »

I don't have access to the php.ini file
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP XML DOM twitter feed

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply