Search code examples
phpxmlxml-parsingstatusnetidentica

Problems Trying to showStatus Using identica-php


I'm using the identica-php to get a single post using showStatus, just like this:

<?php 
    ini_set('display_errors', 1);
    error_reporting(E_ALL);

    include '../scripts/identica.lib.php';
    include '../misc.php';

    // your identi.ca username and password
    $username = $_GET['u'];
    $password = $_GET['p'];
    $userid = $_GET['uid'];
    $postid = $_GET['pid'];

    // initialize the identi.ca class
    $identica = new Identica($username, $password, "Terrarium");

    // fetch the timeline in xml format
    $xml = $identica->showStatus("xml", $postid);

    $identica_status = new SimpleXMLElement($xml);
    $status = $identica_status->status;
    $user = $status->user;

    echo '<div id="singleStatus">' . $status->text . "</div><br />";
    echo '<div class="single_posted_at">' . $status->created_at . " via " . $status->source . '</div>';
    echo '<img src="' . $user->profile_image_url . '" class="identica_image">';
    echo '<a href="http://identi.ca/' . $user->screen_name . '" class="nameURL">' . $user->name . '</a>: ';
?>

But when I try to run the code everything I got is this:
Result of the code

What I'm doing wrong? An example of the XML result: http://pastebin.com/Q52yfQp9

PS: I've tried to show just the XML to do a test and it worked, so it won't be a problem with the Post ID or the XML, but in the code


Solution

  • status is the root element of the XML, so it hasn't a getter in a SimpleXMLElement object. Below your code revisited to work:

    //$identica_status = new SimpleXMLElement($xml);
    //$status = $identica_status->status;
    $status = new SimpleXMLElement($xml);
    $user = $status->user;