本文整理汇总了PHP中Facebook\FacebookRedirectLoginHelper类的典型用法代码示例。如果您正苦于以下问题:PHP FacebookRedirectLoginHelper类的具体用法?PHP FacebookRedirectLoginHelper怎么用?PHP FacebookRedirectLoginHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FacebookRedirectLoginHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: obtainToken
public function obtainToken($callback)
{
$helper = new FacebookRedirectLoginHelper($callback);
if ($this->input->get('code') === null) {
/**
* Required permissions
* public_profile
* email
* read_insights Show analytics data of page in dashboard
* read_page_mailboxes Manage page conversations
* read_mailbox Manage page mailbox
* manage_pages Manage brand pages
* publish_pages Take actions on behalf of page
*/
$loginUrl = $helper->getLoginUrl(array('public_profile', 'user_friends', 'email', 'read_mailbox', 'read_page_mailboxes', 'manage_pages', 'publish_actions', 'publish_pages', 'read_insights'));
Url::redirect($loginUrl);
return null;
} else {
$session = null;
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
} catch (\Exception $ex) {
// When validation fails or other local issues
}
if ($session) {
// Logged in
}
return $session;
}
}
示例2: action_index
public function action_index()
{
try {
$helper = new FacebookRedirectLoginHelper(Config::get('login_url'));
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
} catch (\Exception $ex) {
// When validation fails or other local issues
}
if (isset($session)) {
//login succes
$long_lived_session = $session->getLongLivedSession();
$access_token = $long_lived_session->getToken();
//*** Call api to get user info
$user_info = $this->facebook->get_user_information($access_token);
//*** Check if user has existed
$user = Model_Users::find('first', array('where' => array('fb_id' => $user_info->getId())));
if (empty($user)) {
// Register user
if (Model_Users::register_user($user_info, $access_token)) {
//Success
}
}
//*** Set session for user
Fuel\Core\Session::set('user_token', $long_lived_session->getToken());
Fuel\Core\Session::set('user_id', $user_info->getId());
//*** Redirect to home
\Fuel\Core\Response::redirect('fanpage/index');
} else {
// login fail
$this->template->login_url = $helper->getLoginUrl();
}
}
示例3: apiAction
/**
* @Route("/fb")
*/
public function apiAction()
{
// ustawiamy ID aplikacji i client secret
FacebookSession::setDefaultApplication(FB_APP_ID, FB_APP_SECRET);
// tworzymy helpera do zalogowania się
$helper = new FacebookRedirectLoginHelper(FB_APP_REDIRECT_URI);
// Pobieramy token sesji
try {
$session = $helper->getSessionFromRedirect();
// Logowanie...
} catch (FacebookRequestException $ex) {
// jeśli błąd Facebooka
} catch (\Exception $ex) {
// jeśli ogólnie błąd
}
if ($session) {
// Zalogowany
echo 'Logged';
// pobieramy profil zalogowanego użytkownika
$user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
// obiekt z danymi zalogowanego użytkownika:
var_dump($user_profile);
} else {
// Link do logowania
echo '<a href="' . $helper->getLoginUrl(array('email', 'user_friends')) . '">Login</a>';
}
return $this->render('Api/api.html.twig');
}
示例4: facebook
public function facebook()
{
if (Session::has('flash_notification.message')) {
return view('auth.facebook');
}
$config = config('services.facebook');
session_start();
FacebookSession::setDefaultApplication($config['id'], $config['secret']);
$helper = new FacebookRedirectLoginHelper(route('facebook'));
if (!Input::has('code')) {
return redirect($helper->getLoginUrl(['email']));
}
try {
$session = $helper->getSessionFromRedirect();
$profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
} catch (FacebookRequestException $e) {
flash('Ne pare rău dar a apărut o eroare. <a href="' . route('facebook') . '">Încearcă din nou</a>.', 'danger');
return redirect()->route('facebook');
}
if ($user = $this->userRepo->getByFacebook($profile->getId())) {
return $this->loginUser($user);
}
if (empty($profile->getProperty('email'))) {
flash('<p>Nu am putut citi adresa de email asociată contului tău de Facebook.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o adresă de email validă</p>', 'danger');
return redirect()->route('facebook');
}
if ($this->userRepo->getByEmail($profile->getProperty('email'))) {
flash('<p>Adresa de email asociată contului tău de Facebook este deja folosită pe site de altcineva.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o altă adresă de email.</p>', 'danger');
return redirect()->route('facebook');
}
$user = User::create(['email' => $profile->getProperty('email'), 'first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'avatar' => $this->getFacebookPictureUrl($session), 'role_id' => config('auth.default_role_id'), 'confirmed' => 1, 'county_id' => 20]);
$user->setMeta('facebook', $profile->getId());
$user->save();
return $this->loginUser($user);
}
示例5: index
public function index()
{
FacebookSession::setDefaultApplication(Config::get('facebook.appid'), Config::get('facebook.secret'));
$helper = new FacebookRedirectLoginHelper('http://localhost:8000/home');
// $helper = new FacebookRedirectLoginHelper('http://hexanlyzer.azurewebsites.net/home');
return redirect($helper->getLoginUrl());
}
示例6: login
/**
* login with facebook sdk
*
* @param String $appId, $appSecret, $redirectUrl
*
* @return boolean
*/
public function login($appId, $appSecret, $redirectUrl)
{
$redirectUrl = 'http://' . $_SERVER['HTTP_HOST'] . $redirectUrl;
$request = new Request();
FacebookSession::setDefaultApplication($appId, $appSecret);
$helper = new FacebookRedirectLoginHelper($redirectUrl);
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
} catch (\Exception $ex) {
// When validation fails or other local issues
}
$this->loginurl = $helper->getLoginUrl();
if ($session) {
$FacebookRequest = new FacebookRequest($session, 'GET', '/me');
$response = $FacebookRequest->execute();
$graph = $response->getGraphObject(GraphUser::classname());
$name = $graph->getName();
$accessToken = $session->getAccessToken();
$request->setSession('facebook', (string) $accessToken);
return true;
} else {
return false;
}
}
示例7: getFacebookRedirectLoginHelper
/**
* @return FacebookRedirectLoginHelper
*/
protected function getFacebookRedirectLoginHelper()
{
FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
$helper = new FacebookRedirectLoginHelper($this->getRedirectUrl());
$helper->disableSessionStatusCheck();
return $helper;
}
示例8: connect
/**
* @param $redirect_url
* @return string|Facebook\GraphUser Login URL or GraphUser
*/
function connect($redirect_url)
{
FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
$session = new FacebookSession($_SESSION['fb_token']);
} else {
$session = $helper->getSessionFromRedirect();
}
if ($session) {
try {
$_SESSION['fb_token'] = $session->getToken();
$request = new FacebookRequest($session, 'GET', '/me');
$profile = $request->execute()->getGraphObject('Facebook\\GraphUser');
if ($profile->getEmail() === null) {
throw new \Exception('L\'email n\'est pas disponible');
}
return $profile;
} catch (\Exception $e) {
unset($_SESSION['fb_token']);
return $helper->getReRequestUrl(['email']);
}
} else {
return $helper->getLoginUrl(['email']);
}
}
示例9: facebokLoginHelper
public function facebokLoginHelper($redirect_url, $canvas = false)
{
if ($canvas) {
$helper = new FacebookCanvasLoginHelper();
} else {
$helper = new FacebookRedirectLoginHelper($redirect_url);
}
//missing javascript helper to be added in other relase
// log errors
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
Log::error('Something is wrong from facebook.');
return false;
} catch (\Exception $ex) {
// When validation fails or other local issues
Log::error('Something is wrong with your user validation.');
return false;
}
// work with the session
if ($session) {
return $session;
} else {
//return false to trigger redirect to facebook
return false;
}
}
示例10: getUserInfo
private function getUserInfo()
{
FacebookSession::setDefaultApplication(Config::get('facebook.appid'), Config::get('facebook.secret'));
$helper = new FacebookRedirectLoginHelper('http://localhost:8000/home');
$userID = "";
$userEmail = "";
$userName = "";
$userPicUrl = "";
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
} catch (\Exception $ex) {
// When validation fails or other local issues
}
if (isset($_SESSION['token'])) {
// We have a token, is it valid?
$session = new FacebookSession($_SESSION['token']);
try {
$session->Validate(Config::get('facebook.appid'), Config::get('facebook.secret'));
} catch (FacebookAuthorizationException $ex) {
// Session is not valid any more, get a new one.
$session = '';
}
}
if (isset($session)) {
$_SESSION['token'] = $session->getToken();
$request = new FacebookRequest($session, 'GET', '/me?fields=id,name,email,picture');
$response = $request->execute();
$graphObject = $response->getGraphObject();
$userID = $graphObject->getProperty('id');
$userName = $graphObject->getProperty('name');
$userEmail = $graphObject->getProperty('email');
$userPicObj = $graphObject->getProperty('picture')->asArray();
$userPicUrl = $userPicObj['url'];
$_SESSION['usrID'] = $userID;
$_SESSION['usrName'] = $userName;
$_SESSION['usrEmail'] = $userEmail;
$_SESSION['usrPicUrl'] = $userPicUrl;
$user_model = App\user::where('user_id', $userID)->first();
if (is_null($user_model)) {
$user_model = new App\user();
$user_model->user_id = $userID;
$user_model->user_name = $userName;
$user_model->user_email = $userEmail;
$user_model->user_profilePic = $userPicUrl;
$user_model->save();
} else {
$user_model->user_name = $userName;
$user_model->user_email = $userEmail;
$user_model->user_profilePic = $userPicUrl;
$user_model->save();
}
}
$data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
$data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
return $data;
}
示例11: getSessionOnLogin
/**
* Get the Facebook session on redirect
* @return bool|Facebook\FacebookSession
*/
function getSessionOnLogin()
{
$helper = new Facebook\FacebookRedirectLoginHelper(\Idno\Core\site()->config()->getDisplayURL() . 'facebook/callback');
try {
return $helper->getSessionFromRedirect();
} catch (\Exception $e) {
return false;
}
}
示例12: facebook
public function facebook()
{
$facebook_default_scope = explode(',', $this->ci->config->item("facebook_default_scope"));
$facebook_app_id = $this->ci->config->item("facebook_app_id");
$facebook_api_secret = $this->ci->config->item("facebook_api_secret");
// init app with app id and secret
FacebookSession::setDefaultApplication($facebook_app_id, $facebook_api_secret);
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper(site_url('login/facebook'));
// see if a existing session exists
if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
// create new session from saved access_token
$session = new FacebookSession($_SESSION['fb_token']);
// validate the access_token to make sure it's still valid
try {
if (!$session->validate()) {
$session = null;
}
} catch (Exception $e) {
// catch any exceptions
$session = null;
}
}
if (!isset($session) || $session === null) {
// no session exists
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
// handle this better in production code
print_r($ex);
} catch (Exception $ex) {
// When validation fails or other local issues
// handle this better in production code
print_r($ex);
}
}
// see if we have a session
if (isset($session)) {
// save the session
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession($session->getToken());
// graph api request for user data
//$request = new FacebookRequest($session, 'GET', '/me/friends');
$request = new FacebookRequest($session, 'GET', '/me?fields=id,name,picture,friends');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject()->asArray();
$fb_data = array('me' => $graphObject, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
$this->ci->session->set_userdata('fb_data', $fb_data);
} else {
$fb_data = array('me' => null, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
$this->ci->session->set_userdata('fb_data', $fb_data);
}
return $fb_data;
}
示例13: __invoke
/**
*
* @param string $value
* @return string
*/
public function __invoke($value = 'your/redirect/URL/here')
{
$config = $this->getServiceLocator()->getServiceLocator()->get('Config');
FacebookSession::setDefaultApplication($config['facebook']['appId'], $config['facebook']['secret']);
//TODO should this be in a global space
$server = isset($_SERVER['HTTP_HOST']) ? "http://" . $_SERVER['HTTP_HOST'] : 'http://0.0.0.0';
$helper = new FacebookRedirectLoginHelper($server . $value);
return $helper->getLoginUrl();
}
示例14: facebook_helper
public function facebook_helper()
{
$redirectUrl = $this->facebook["callback_url"];
$helper = new FacebookRedirectLoginHelper($redirectUrl);
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookSDKException $e) {
$session = null;
}
return compact('helper', 'session');
}
示例15: testLogoutURL
public function testLogoutURL()
{
$helper = new FacebookRedirectLoginHelper(self::REDIRECT_URL, FacebookTestCredentials::$appId, FacebookTestCredentials::$appSecret);
$logoutUrl = $helper->getLogoutUrl(FacebookTestHelper::$testSession, self::REDIRECT_URL);
$params = array('next' => self::REDIRECT_URL, 'access_token' => FacebookTestHelper::$testSession->getToken());
$expectedUrl = 'https://www.facebook.com/logout.php?';
$this->assertTrue(strpos($logoutUrl, $expectedUrl) !== false);
foreach ($params as $key => $value) {
$this->assertTrue(strpos($logoutUrl, $key . '=' . urlencode($value)) !== false);
}
}