iT邦幫忙

0

facebook app 遇到問題,求解決

qaw3388 5 年前3550 瀏覽

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);
}

海綿寶寶 iT邦超人 1 級 ‧ 5 年前 檢舉
昨天還剛學寫程式
今天就在寫facebook app了
真厲害
讚讚讚
qaw3388 iT邦新手 5 級 ‧ 5 年前 檢舉
沒~我根本都從網路找到的訊息亂湊,哈哈哈哈!!!

1 個回答

4
wonton
iT邦高手 6 級 ‧ 5 年前
最佳解答

PHP 的變數有大小寫之分,你的變數Facebook 的F是大寫還是小寫?

qaw3388 iT邦新手 5 級 ‧ 5 年前 檢舉

小寫

我要發表回答

立即登入回答