- 從developers.facebook.com下載SDK並上傳文件夾「Facebook」到您的網站空間;
- 創建Facebook應用程序;
-put這個代碼在 「臉譜」 的同一個文件夾:
<?php
session_start();
require_once('Facebook/Entities/AccessToken.php');
require_once('Facebook/FacebookSession.php');
require_once('Facebook/FacebookRedirectLoginHelper.php');
require_once('Facebook/HttpClients/FacebookHttpable.php');
require_once('Facebook/HttpClients/FacebookCurl.php');
require_once('Facebook/HttpClients/FacebookCurlHttpClient.php');
require_once('Facebook/FacebookRequest.php');
require_once('Facebook/FacebookResponse.php');
require_once('Facebook/FacebookSDKException.php');
require_once('Facebook/FacebookRequestException.php');
require_once('Facebook/FacebookAuthorizationException.php');
require_once('Facebook/GraphObject.php');
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('EDIT THIS','EDIT THIS');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('EDIT THIS');
try {
$session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
// When Facebook returns an error
} catch(Exception $ex) {
// When validation fails or other local issues
}
// see if we have a session
if (isset($session)) {
// graph api request for user data
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$email = $graphObject->getProperty('email');
$firstname = $graphObject->getProperty('first_name');
$lastname = $graphObject->getProperty('last_name');
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl() . '">Get information</a>';
}
?>
在這裏找到... http://metah.ch/blog/2014/05/facebook-sdk-4-0-0 -for-php-a-working-sample-to-get-started /感謝您的辛勤工作! – JRomeo 2014-09-05 08:19:05