Hola a todos tengo el siguiente problema estoy utilizando RSS Reader (un .php que se encarga de mostrar en mi web los RSS que yo desee) funciona todo de maravilla, he podido incluir RSS de los foros SMF sin problema alguno, el problema comienza acá.
Estoy intentando agregar un RSS de Facebook, el problema que tengo es que al configurarlo dentro del php, este no me acepta el carácter &:
https://www.facebook.com/feeds/notifications.php?id=319579974767006&viewer=1074983523&key=AWhjAKL7r9fCfZlH&format=rss20
Por lo que tengo que modificarlo por &:, funciona de maravilla el problema está que facebook no me lo permite con el & que acompaña a format:
https://www.facebook.com/feeds/notifications.php?id=319579974767006&:viewer=1074983523&:key=AWhjAKL7r9fCfZlH&:format=rss20
si lo cambio por &: ya no me funciona el link, mi pregunta es como podría agregarlo dentro de RSS Reader sin tener que cambiar las "&"?
Gracias
A mi:
https://www.facebook.com/feeds/notifications.php?id=319579974767006&viewer=1074983523&key=AWhjAKL7r9fCfZlH&format=rss20
Me lo publica bien y sin problemas :S
De todos modos puedes usar un acortador.
Claro que funciona perfectamente, quizás me expresé mal, cuando lo paso al RSS Reader este no me acepta los &, por ende los cambié por &: y ahí no me funciona :S
El problema es con el parse entonce, una buena idea es la de dimitrix, acortar la URL.
También puedes ocupar este parse xD.
index.php
<?php
require_once('feed.php');
$feed = new FeedComponent();
print_r($feed->parser('https://www.facebook.com/feeds/notifications.php?id=319579974767006&viewer=1074983523&key=AWhjAKL7r9fCfZlH&format=rss20'));
feed.php
<?php
class FeedComponent {
protected $URL = NULL;
public function parser($site) {
$result = null; //Variable que retornara el Feed ya parseado
$this->URL = $site;
$source = $this->getSource($this->URL);
$xmlSource = new SimpleXMLElement($source, LIBXML_NOCDATA);
//Detecta si el Feed es tipo Atom...
if(preg_match('/<feed[^>]+>/i', $source)) {
$result = $this->AtomParser($xmlSource);
//Detecta si el Feed es tipo RSS...
}elseif(preg_match('/<rss[^>]+>/i', $source)) {
$result = $this->RssParse($xmlSource);
}
//Retorno el contenido...
return (empty($result)) ? NULL : $result;
}
//Function para obtener el codigo de fuente de un archivo Feed
protected function getSource($site) {
$this-> URL = $site;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4');
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $site);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
//Metodo para parsear Feed tipo Atom...
protected function AtomParser($xmlSource) {
$temp;
foreach($xmlSource->entry as $arts) {
$temp[] = array('titulo' => $arts->title, 'articulo' => $arts->content, 'url' => $arts->link[4]->attributes()->href);
}
return $temp;
}
//Metodo para parsear Feed tipo RSS
protected function RssParse($xmlSource) {
$temp = null;
foreach($xmlSource->channel->item as $arts) {
$temp[] = array('titulo' => $arts->title, 'articulo' => $arts->children('content', TRUE), 'url' => $arts->{'link'});
}
return $temp;
}
}
?>
Hola, me muestra el siguiente error:
CitarFatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\hola\feed.php:13 Stack trace: #0 C:\xampp\htdocs\hola\feed.php(13): SimpleXMLElement->__construct('', 16384) #1 C:\xampp\htdocs\hola\index.php(6): FeedComponent->parser('https://www.fac...') #2 {main} thrown in C:\xampp\htdocs\hola\feed.php on line 13
Saludos
Encontré un simple "feed reader", lo he probado y funciona genial, ahora al momento de probarlo con facebook sucede lo mismo, queda en blanco:
<?php
//$RSS = new LectorRSS ("http://www.tublogenwordpress.com/blog/feed/rss/");
$RSS = new LectorRSS ("https://www.facebook.com/feeds/notifications.php?id=319579974767006&viewer=1074983523&key=AWhjAKL7r9fCfZlH&format=rss20");
class LectorRSS {
var $url;
var $data;
function LectorRSS ($url){
$this->url;
$this->data = implode ("", file ($url));
}
function obtener_items (){
preg_match_all ("/<item .*>.*<\/item>/xsmUi", $this->data, $matches);
$items = array ();
foreach ($matches[0] as $match){
$items[] = new RssItem ($match);
}
return $items;
}
}
class RssItem {
var $title, $url;
function RssItem ($xml){
$this->populate ($xml);
}
function populate ($xml){
preg_match ("/<title> (.*) <\/title>/xsmUi", $xml, $matches);
$this->title = $matches[1];
preg_match ("/<link> (.*) <\/link>/xsmUi", $xml, $matches);
$this->url = $matches[1];
}
function obtener_titulo (){
return $this->title;
}
function obtener_url (){
return $this->url;
}
}
foreach ($RSS->obtener_items () as $item){
printf ('<a target="_BLANK" href="%s">%s</a><br />',
$item->obtener_url (), $item->obtener_titulo ());
}
?>
a ver si me iluminan, saludos