0

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

4

3 回答 3

1

The problem isn't identica-php, it's how you're trying to use SimpleXMLElement. Your $identica_status->user property is not an array, it's an iterable and accessible object (according to the PHP docs).

try:

$user = $identica_status->user->children();

or it might be simpler to just access elements further down in the document tree like this:

$identica_status->user->screen_name
于 2011-09-10T23:09:44.803 回答
1

status 是 XML 的根元素,因此它在 SimpleXMLElement 对象中没有 getter。在您的代码下方重新访问以工作:

//$identica_status = new SimpleXMLElement($xml);
//$status = $identica_status->status;
$status = new SimpleXMLElement($xml);
$user = $status->user;
于 2011-10-14T10:50:12.077 回答
0

您链接到的这个库非常非常古老(09 年 9 月),从那时起,StatusNet 已经发展了很多。我并不惊讶这不再起作用。

但是,由于 Identica 的 API 与 Twitter 的相似,您可能可以使用 Twitter PHP 库来做您想做的事情。

于 2011-09-08T17:26:50.097 回答