本文整理汇总了PHP中Facebook::setDefaultAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::setDefaultAccessToken方法的具体用法?PHP Facebook::setDefaultAccessToken怎么用?PHP Facebook::setDefaultAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook
的用法示例。
在下文中一共展示了Facebook::setDefaultAccessToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postLogin
public function postLogin()
{
if (\Input::get('fb_access_token')) {
\Facebook::setDefaultAccessToken(\Input::get('fb_access_token'));
try {
$response = \Facebook::get('/me?fields=id');
$fbUserId = $response->getGraphUser()->getProperty('id');
$fbUser = FbUser::firstOrNew(['fb_user_id' => $fbUserId]);
if ($fbUser->save()) {
\Session::put('fb_user_id', $fbUserId);
return \Response::json(['success' => true]);
}
} catch (\Facebook\Exceptions\FacebookSDKException $e) {
return \Response::json(['success' => false, 'errors' => [$e->getMessage()]]);
}
}
return \Response::json(['success' => false]);
}
示例2: catch
$accessToken = $_SESSION['facebook_access_token'];
} else {
$accessToken = $helper->getAccessToken();
}
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
if (isset($_SESSION['facebook_access_token'])) {
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
} else {
$_SESSION['facebook_access_token'] = (string) $accessToken;
// OAuth 2.0 client handler
$oAuth2Client = $fb->getOAuth2Client();
// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}
// validating the access token
try {
$request = $fb->get('/me');
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
if ($e->getCode() == 190) {