2011-01-06 5 views
-1

그럼 난 페이스 북의 벽에 게시하려고하지만 난이 오류를 얻을 :치명적인 오류 : 정의되지 않은 메서드 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

답변

0

글쎄, 오류 메시지로 작성되었으므로 $ facebook-> api_client에 "stream_publish"메소드가 없습니다. 사용중인 라이브러리의 설명서를 참조하여 페이스 북에 연결하십시오.

$facebook->api_client->session_key = FB_SESSION; 

가 만들 것 PHP가 자동으로 입력 stdClass의 객체에 $facebook->api_client 캐스트 : $facebook->api_client 만약

0

는, 행, 객체가 아닙니다. 어떤 코드가 나중에 코드를 작성하면 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이 null 인 이유를 조사해야합니다.

관련 문제