2011-09-07 54 views
0

我使用identica-php使用showStatus得到一個職位,就像這樣:問題試圖showStatus使用identica-PHP

<?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>: '; 
?> 

但是當我嘗試運行代碼的一切我是這樣的:
Result of the code

我做錯了什麼? XML結果的一個例子:http://pastebin.com/Q52yfQp9

PS:我試圖只顯示XML來做一個測試,它的工作,所以它不會是Post ID或XML的問題,但在代碼

回答

1

狀態是XML的根元素,所以它不是招在SimpleXMLElement對象中是一個getter。 下面的代碼重新工作:

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

非常感謝!+50獲得**:)** –

0

您鏈接到的這個庫真的很舊(09年9月),並且StatusNet從那以後發展了很多。我不驚訝,這不起作用了。

但是,由於Identica的API與Twitter相似,因此您可以使用Twitter PHP庫來執行您想要的操作。

1

問題不是identica-php,它是你如何使用SimpleXMLElement。您的$ identica_status->用戶屬性不是數組,它是一個可迭代且可訪問的對象(根據the PHP docs)。

嘗試:

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

或者它可能是簡單的,只是訪問的元素文檔樹這樣的進一步下跌:

$identica_status->user->screen_name 
+0

第一個返回此錯誤:'致命錯誤:調用一個成員函數的孩子()一個非對象在/用戶/彌敦道/網站/水晶球/標籤/ showpost.php在第24行,第二個返回與問題**中顯示的相同的內容:(** –