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
$user开发者_开发问答name = $_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:
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
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;
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
This library you're linking to is really, really old (sept '09) and StatusNet has evolved a lot since then. I'm not surprised this does not work anymore.
However, since Identica's API is similar to Twitter's, you could probably use a Twitter PHP library to do what you want.
精彩评论