我無法弄清楚如何更改這個簡單的代碼以使用最新的facebook SDK ... 看起來他們已經改變了一些變量以及檢索信息的方式。我之前沒有和facebook SDK一起工作過,在編程方面不太好。準備好文檔並嘗試了幾件事情後,我仍然失敗。所以,我希望一些你們可以幫助我在這裏...將php更改爲新的facebook SDK
require("src/facebook.php");
// construct the object with your facebook app data
$facebook = new Facebook(array(
'appId' => '[YOUR APP ID]',
'secret' => '[YOUR APP SECRET ID]',
'cookie' => true
));
try {
// to get the id of the currently logged in user
// if, you want you can manually set a user id here like this:
//$uid = '[FB USER ID]';
$uid = $facebook->getUser();
// if you know know the access token before hand then you can set it here
// or you can leave this line commented
//$facebook->setAccessToken([ACCESS TOKEN FOR THIS USER - APP]);
$api_call = array(
'method' => 'users.hasAppPermission',
'uid' => $uid,
'ext_perm' => 'publish_checkins'
);
$can_post = $facebook->api($api_call);
if ($can_post) {
$facebook->api('/'.$uid.'/checkins', 'POST', array(
'access_token' => $facebook->getAccessToken(),
'place' => '[LOCATION ID]',
'message' => 'I am place to check in',
'picture' => 'http://test.com/someplace.png',
'coordinates' => json_encode(array(
'latitude' => '[LATITUDE]',
'longitude' => '[LONGITUDE]',
'tags' => '[A LIST OF TAGS TO USE FOR THIS CHECKIN]'))
));
echo 'You are checked in';
} else {
die('Permissions required!');
}
} catch (Exception $e){
// No user found - ask the person to login
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
那麼,什麼是錯誤? – Peter