本文整理匯總了PHP中Facebook\GraphUser::classname方法的典型用法代碼示例。如果您正苦於以下問題:PHP GraphUser::classname方法的具體用法?PHP GraphUser::classname怎麽用?PHP GraphUser::classname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Facebook\GraphUser
的用法示例。
在下文中一共展示了GraphUser::classname方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: loginWithToken
/**
* login with token
*
* @param String $accessToken, $appId, $appSecret
*
* @return boolean
*/
public function loginWithToken($accessToken, $appId, $appSecret)
{
FacebookSession::setDefaultApplication($appId, $appSecret);
$session = new FacebookSession($accessToken);
$FacebookRequest = new FacebookRequest($session, 'GET', '/me');
$response = $FacebookRequest->execute();
$this->graph = $response->getGraphObject(GraphUser::classname());
if ($session) {
return true;
}
return false;
}
示例2: FacebookRedirectLoginHelper
FacebookSession::setDefaultApplication($app_id, $app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
$sess = $helper->getSessionFromRedirect();
//check if facebook session exists
if (isset($_SESSION['fb_token'])) {
$sess = new FacebookSession($_SESSION['fb_token']);
}
//logout
$logout = 'http://packetcode.com/apps/newfblogin&logout=true';
//4. if fb sess exists echo name
if (isset($sess)) {
//store the token in the php session
$_SESSION['fb_token'] = $sess->getToken();
//create request object,execute and capture response
$request = new FacebookRequest($sess, 'GET', '/me');
// from response get graph object
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::classname());
// use graph object methods to get user details
$name = $graph->getName();
$id = $graph->getId();
$image = 'https://graph.facebook.com/' . $id . '/picture?width=300';
$email = $graph->getProperty('email');
echo "hi {$name} <br>";
echo "your email is {$email} <br><Br>";
echo "<img src='{$image}' /><br><br>";
echo "<a href='" . $logout . "'><button>Logout</button></a>";
} else {
//else echo login
echo '<a href="' . $helper->getLoginUrl(array('email')) . '" >Login with facebook</a>';
}