PO塗鴉牆,最後會顯示>>Fatal error: Call to a member function api() on a non-object in ../APP/index.php on line 46
$ret = $Facebook->api('/'.$uid.'/feed/', 'post', $attachment)
這行有什麼問題嗎?
[code]<?php
require '/home/rohocomt/public_html/apps2/sdk/facebook.php';
$facebook = new Facebook(array(
'appId' => '24713944539xxx',
'secret' => '7b9440c62786d08f2fd24964ffbbxxxx',
'cookie' => true,
));
$uid = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl( array( 'scope' => 'publish_stream', 'next' => 'http://www.facebook.com/alwayshaha','canvas' => 1, 'fbconnect' => 0 ));
if($uid) {
try {
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$uid = null;
$me = null;
}
}else{
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}
$permissions = $facebook->api("/me/permissions");
if(!array_key_exists('publish_stream', $permissions['data'][0]) ) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}
?>
<?php
if(isset($_POST['q1'])){
$ans = $_POST['q1'];
if($ans == 'a'){
$result = '相當有創意';
}else if($ans == 'b'){
$result = '相當屌';
}else if($ans == 'c'){
$result = '相當智障';
}else if($ans == 'd'){
$result = '相當好笑';
}
}else if(isset($_POST['sendpost'])){
$result = $_POST['ans_text'];
$attachment = array(
'message' => $result,
'actions' => array( array('name' => '玩心理測驗', 'link' => 'apps.facebook.com/wtfappp/'))
);
$ret = $Facebook->api('/'.$uid.'/feed/', 'post', $attachment);
}