Парсинг Twitter через Geocode не может отобразить ссылку на статус - PullRequest
2 голосов
/ 04 февраля 2012

В настоящее время я разбираю твиты в твиттере по геокодированию и отображаю их с помощью php. Но в данный момент я не могу отобразить ссылку на твит.

Но в XML это feed-> entry ->

<link type="text/html" href="http://twitter.com/OFFICIALGRINZ/statuses/165838159928762368" rel="alternate" >

Возможно ли получить доступ к URL-адресу из этого тега?

Вот мой код.

<?php
 $tabTitle = ' | Twitter';
$pageIntroductionHeading = 'Twitter';
$pageIntroductionContent = 'Twitter';
$column1Heading = 'London';
$column2Heading = 'New York';
$column3Heading = 'Paris';

require_once 'header.php';
 require_once 'navigationMenu.php';

 ?>

<?php require_once 'getWeather.php'; ?>
 <?php require_once 'getExchangeRates.php'; ?>

 <?php require_once 'pageIntroduction.php'; ?>


 <div id="obsah" class="content box">
<div class="in">
    <div class="shadow">
        <img src="./img/threeCities.jpg" alt="Three Cities Banner" title="Three Cities" class="thumb" />
    </div>
    <ul class="columns">
        <li class="col1">
            <h3><?php
if (isset($column1Heading)) {
echo $column1Heading;
}
?></h3>
            <p>

              <?php 
               $feed = simplexml_load_file ('http://search.twitter.com/search.atom?geocode=51.5069999695%2C-0.142489999533%2C10.0mi%22london%22&lang=en&rpp=5');
                if ($feed){foreach ($feed->entry as $item) {

                         echo '<a href=\'' . $item->author->uri. '\'>' . $item->title .         '</a>', '</br>' . $item->published, '</br>';
                    }
                    }
                    else echo "Cannot find Twitter feed!"
                     ?>


            </p>
        </li>
        <li class="col2">

        </li>
    </ul>
    <div class="clear"></div>
</div>
    <?php require_once 'footer.php'; ?>

1 Ответ

0 голосов
/ 07 февраля 2012

Вы можете использовать DomDocument Parser и DomXPath для доступа к вашей ссылке.

$dom = new DomDocument();
$dom->load('yourfeed.xml');
$xpath = new DomXPath($dom);
$links = $xpath->query('/feed/entry/link'); // returns a DomNodeList with 0 or more elements
foreach ($links as $link)
{
    // $link->getAttribute('href');
}

Этот код не проверен.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...