本文整理汇总了PHP中Facebook\FacebookRedirectLoginHelper::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP FacebookRedirectLoginHelper::getAccessToken方法的具体用法?PHP FacebookRedirectLoginHelper::getAccessToken怎么用?PHP FacebookRedirectLoginHelper::getAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\FacebookRedirectLoginHelper
的用法示例。
在下文中一共展示了FacebookRedirectLoginHelper::getAccessToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMe
/**
* Return info about facebook user
* @param $fields
* @return array
* @throws Exception
*/
public function getMe($fields)
{
$client = $this->fb->getOAuth2Client();
$accessTokenObject = $this->helper->getAccessToken();
if ($accessTokenObject == null) {
throw new Exception("User not allowed permissions");
}
if ($fields == "" || !is_array($fields) || count($fields) == 0) {
//array is empty
$fields = array(ID);
//set ID field
}
try {
$accessToken = $client->getLongLivedAccessToken($accessTokenObject->getValue());
$response = $this->fb->get("/me?fields=" . implode(",", $fields), $accessToken);
$this->setSocialLoginCookie(self::SOCIAL_NAME);
return $response->getDecodedBody();
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
throw new Exception($e->getMessage());
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
throw new Exception($e->getMessage());
}
}
示例2: getMe
/**
* Return info about login user
* @return array
* @throws Exception
*/
public function getMe()
{
$client = $this->fb->getOAuth2Client();
$accessTokenObject = $this->helper->getAccessToken();
if ($accessTokenObject == null) {
throw new Exception("User not allowed permissions");
}
try {
$accessToken = $client->getLongLivedAccessToken($accessTokenObject->getValue());
$response = $this->fb->get('/me?fields=id,name,email', $accessToken);
return $response->getDecodedBody();
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
throw new Exception($e->getMessage());
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
throw new Exception($e->getMessage());
}
}