尝试使用identica php显示状态时出现问题
我使用尝试使用identica php显示状态时出现问题,php,xml,xml-parsing,statusnet,identica,Php,Xml,Xml Parsing,Statusnet,Identica,我使用showStatus获取单个帖子,如下所示: <?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']; $pas
showStatus
获取单个帖子,如下所示:
<?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>: ';
?>
$identica_status->user->screen_name
showStatus(“xml”,$postid);
$identica_status=新的simplexmlement($xml);
$status=$identica_status->status;
$user=$status->user;
回显“”$状态->文本。“
”;
回显“”$状态->在上创建。“通过”$状态->来源。“;
回显“配置文件\图像\ url”“class=”identica_image“>”;
回声':';
?>
但是当我尝试运行代码时,我得到的结果是:我做错了什么?XML结果的一个示例:
PS:我试着只显示XML来进行测试,它成功了,因此Post ID或XML不会有问题,但是在代码中,您链接到的这个库非常非常非常古老(09年9月),自那以后StatusNet已经发展了很多。我不奇怪这不再有效
然而,由于Identica的API与Twitter相似,您可能可以使用Twitter PHP库来做您想做的事情。问题不在于Identica PHP,而在于您如何尝试使用simplexmlement。您的$Identica_status->user属性不是数组,而是一个可编辑且可访问的对象(根据) 尝试: 或者,只访问文档树中较低的元素可能更简单,如下所示:
<?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>: ';
?>
$identica_status->user->screen_name
status是XML的根元素,因此它在SimpleXMLElement对象中没有getter。 下面是重新访问您的代码以工作:
//$identica_status = new SimpleXMLElement($xml);
//$status = $identica_status->status;
$status = new SimpleXMLElement($xml);
$user = $status->user;
第一个返回了此错误:
致命错误:在第24行的/Users/Nathan/Sites/Terrarium/tabs/showpost.php中对非对象调用成员函数children(),第二个返回了与问题中所示相同的内容:(