No passado ensinei como apresentar o contador de feeds em texto, numa altura em que os feeds eram distribuidos pelos servidores da Feedburner. Nesta altura os feeds foram alterados para os servidores da Google e o método de apresentação do contador de feeds mudou também. A dica de hoje é precisamente como dar a volta a esse problema e voltar a apresentar o seu contador de feeds bonitinho!
O CÓDIGO ANTIGO DO FEEDBURNER:
//get cool feedburner count
$whaturl=”http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id”;//Initialize the Curl session
$ch = curl_init();//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);//Execute the fetch
$data = curl_exec($ch);//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry[‘circulation’];
//end get cool feedburner count
A SOLUÇÃO PARA O NOVO CONTADOR DO GOOGLE:
Substitua esta linha de código do exemplo anterior:
//get cool feedburner count
$whaturl=”http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id”;
Por esta nova linha de código:
//get cool feedburner count
$whaturl=”https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id”;
EXEMPLO DO CÓDIGO COMPLETO:
//get cool feedburner count
$whaturl=”https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id”;//Initialize the Curl session
$ch = curl_init();//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);//Execute the fetch
$data = curl_exec($ch);//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry[‘circulation’];
//end get cool feedburner count
NOTAS IMPORTANTES:
- Não se esqueça de substituir a porção de código que diz ‘feedburner-id’ pelo seu actual ID do serviço;
- O SimpleXMLElements necessita da versão PHP5 para funcionar. Se o seu contador não aparecer, é porque provavelmente o seu servidor ainda está em PHP4!