2011-01-06 114 views
-1

嗯,我正在嘗試在Facebook上發佈的牆上,但我得到這個錯誤:致命錯誤:調用未定義的方法stdClass的:: stream_publish()

Fatal error: Call to undefined method stdClass::stream_publish()

我想要的代碼是這個

<?php 

define('FB_APIKEY', '<Your Api Key>'); 
define('FB_SECRET', '<Secret>'); 
define('FB_SESSION', '<Session>'); 

require_once('facebook.php'); 

echo "post on wall"; 
echo "<br/>"; 

try { 
$facebook = new Facebook(FB_APIKEY, FB_SECRET); 
$facebook->api_client->session_key = FB_SESSION; 
$facebook->api_client->expires = 0; 
$message = ''; 

$attachment = array(
'name' => $_POST["name"], 
'href' => $_POST["href"], 
'description' => $_POST["description"], 
'media' => array(array('type' => 'image', 
'src' => $_POST["src"], 
'href' => $_POST["href"]))); 

$action_links = array(array('text' => 'Visit Us', 'href' => '<link to some place here>')); 

$attachment = json_encode($attachment); 
$action_links = json_encode($action_links); 

$target_id = "<Target Id>"; 
$session_key = FB_SESSION; 

if($facebook->api_client->stream_publish($message, $attachment, $action_links, null, $target_id)) { 
echo "Added on FB Wall"; 
} 
} catch(Exception $e) { 
echo $e . "<br />"; 
} 
?> 
+0

你正在使用什麼庫?真正的問題在哪裏? – Ivan 2011-01-06 17:07:15

回答

0

那麼,因爲它寫在錯誤消息中沒有方法「stream_publish」在$ facebook-> api_client中。 請查閱您用來連接到Facebook的圖書館的手冊。

0

如果$facebook->api_client不是對象,則該行:

$facebook->api_client->session_key = FB_SESSION; 

將使PHP默默地投$facebook->api_clientstdClass類型的對象。後面的代碼會導致你得到的Fatal error: Call to undefined method stdClass::stream_publish()

嘗試改變: ...

$facebook = new Facebook(FB_APIKEY, FB_SECRET); 
$facebook->api_client->session_key = FB_SESSION; 
$facebook->api_client->expires = 0; 

... 

趕上的時候api_client是假的(或者,也許不是一個對象):

... 

$facebook = new Facebook(FB_APIKEY, FB_SECRET); 

if (!($facebook->api_client)) { 
    //throw error 
    echo 'Need to sort this bit out'; 
    exit; 
} 

$facebook->api_client->session_key = FB_SESSION; 
$facebook->api_client->expires = 0; 

... 

然後,如果不拋出錯誤,您需要調查爲什麼$facebook->api_client爲空。

相關問題