ksduded Posted July 31, 2009 Share Posted July 31, 2009 I am trying to place a twitter feed on my php page. I am following this tutorial: http://frankkoehl.com/2008/11/display-twitter-updates-on-your-website/ It uses the cURL functions. I have php 5+ so I am assuming its built in. However I get the error: Fatal error: Call to undefined function twitter_status() The programmer of the code suggested to ask other php'ers, so I present my case to you. I have put the fuction twitter_status(etc..... inside the <head> tags within <script type='text/javascript'> This is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type='text/javascript'> function twitter_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($c, CURLOPT_TIMEOUT, 5); $response = curl_exec($c); $responseInfo = curl_getinfo($c); curl_close($c); if (intval($responseInfo['http_code']) == 200) { if (class_exists('SimpleXMLElement')) { $xml = new SimpleXMLElement($response); return $xml; } else { return $response; } } else { return false; } } <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </script> <title>Untitled Document</title> </head> <ul> <?php if ($twitter_xml = twitter_status('61289623')) { foreach ($twitter_xml->status as $key => $status) { ?> <li><?php echo $status->text; ?></li> <?php ++$i; if ($i == 1) break; } ?> <li><a href="http://twitter.com/YOUR_PROFILE_HERE">more...</a></li> <?php } else { echo 'Sorry, Twitter seems to be unavailable at the moment...again...'; } ?> </ul> <body> </body> </html> any help will be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/ Share on other sites More sharing options...
rhodesa Posted July 31, 2009 Share Posted July 31, 2009 um...your twitter_status() function is defined as JavaScript not PHP.... Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887650 Share on other sites More sharing options...
rhodesa Posted July 31, 2009 Share Posted July 31, 2009 Try this instead: <?php function twitter_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($c, CURLOPT_TIMEOUT, 5); $response = curl_exec($c); $responseInfo = curl_getinfo($c); curl_close($c); if (intval($responseInfo['http_code']) == 200) { if (class_exists('SimpleXMLElement')) { $xml = new SimpleXMLElement($response); return $xml; } else { return $response; } } else { return false; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <ul> <?php if ($twitter_xml = twitter_status('61289623')) { foreach ($twitter_xml->status as $key => $status) { ?> <li><?php echo $status->text; ?></li> <?php ++$i; if ($i == 1) break; } ?> <li><a href="http://twitter.com/YOUR_PROFILE_HERE">more...</a></li> <?php } else { echo 'Sorry, Twitter seems to be unavailable at the moment...again...'; } ?> </ul> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887652 Share on other sites More sharing options...
ksduded Posted July 31, 2009 Author Share Posted July 31, 2009 Try this instead: <?php function twitter_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($c, CURLOPT_TIMEOUT, 5); $response = curl_exec($c); $responseInfo = curl_getinfo($c); curl_close($c); if (intval($responseInfo['http_code']) == 200) { if (class_exists('SimpleXMLElement')) { $xml = new SimpleXMLElement($response); return $xml; } else { return $response; } } else { return false; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <ul> <?php if ($twitter_xml = twitter_status('61289623')) { foreach ($twitter_xml->status as $key => $status) { ?> <li><?php echo $status->text; ?></li> <?php ++$i; if ($i == 1) break; } ?> <li><a href="http://twitter.com/YOUR_PROFILE_HERE">more...</a></li> <?php } else { echo 'Sorry, Twitter seems to be unavailable at the moment...again...'; } ?> </ul> <body> </body> </html> I tried that and got this error instead: Fatal error: Call to undefined function curl_init() I am guessing that my php does not include the cURL library? It is php 5+ so I assumed that it should be included Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887654 Share on other sites More sharing options...
GingerRobot Posted July 31, 2009 Share Posted July 31, 2009 I am guessing that my php does not include the cURL library? It is php 5+ so I assumed that it should be included Your guess is correct. Are you using free hosting? I've known it be disabled on those kind of hosts before. Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887674 Share on other sites More sharing options...
ksduded Posted July 31, 2009 Author Share Posted July 31, 2009 I am guessing that my php does not include the cURL library? It is php 5+ so I assumed that it should be included Your guess is correct. Are you using free hosting? I've known it be disabled on those kind of hosts before. i am using a dedicated server with iweb.com and I can't find the php.ini .... there is a comment that i need to remove to make cURL work.... WHM is too confusing Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887685 Share on other sites More sharing options...
TeNDoLLA Posted July 31, 2009 Share Posted July 31, 2009 You can use phpinfo(); to see if curl is actually there or not. Also lots of other information about your settings. <?php phpinfo(); in php.ini search for line ";extension=php_curl.dll" and remove the semicolon in front of the line and restart service. Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887687 Share on other sites More sharing options...
jonsjava Posted July 31, 2009 Share Posted July 31, 2009 I decided to look at Twitters API to see how easy it is to grab stuff. Here's a script I built a couple minutes ago to help you. <?php function getTweets($user){ $count = 0; $xml = simplexml_load_file("http://search.twitter.com/search.atom?q=from:".$user); foreach ($xml->entry as $val){ $output[$count]['published'] = (string)$val->published; $output[$count]['direct_link'] = (string)$val->link->attributes()->href; $output[$count]['message'] = (string)$val->title; $count++; } return $output; } $array = getTweets("jonsjava"); print_r($array); ?> change the user to your user. (where it says getTweets("jonsjava") change jonsjava) Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887790 Share on other sites More sharing options...
rhodesa Posted July 31, 2009 Share Posted July 31, 2009 yeah, keep it simple....just getting a remote file like that doesn't need cURL. cURL is nice, but in this case it's like using a sledgehammer to hang a picture Link to comment https://forums.phpfreaks.com/topic/168289-php-and-twitter/#findComment-887825 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.