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()); }
/** * Execute the job. * * @return void */ public function handle() { // Same time next week! :D $job = (new \App\Jobs\WeeklyMail())->delay(604800); $this->dispatch($job); // We'll just want to double-check our Facebook events still exist // before we email people about them... FacebookSession::setDefaultApplication(getenv('FB_ID'), getenv('FB_SECRET')); $session = FacebookSession::newAppSession(); try { $session->validate(); } catch (FacebookRequestException $ex) { // Session not valid, Graph API returned an exception with the reason. dd($ex); } catch (\Exception $ex) { // Graph API returned info, but it may mismatch the current app or have expired. dd($ex); } $all_events = Event::where('time', '>', date('Y-m-d H:i:s'))->where('time', '<', date('Y-m-d H:i:s', time() + 604800))->get(); foreach ($all_events as $event) { $request = new FacebookRequest($session, 'GET', "/" . $event->facebook_id); try { $response = $request->execute(); } catch (\Exception $ex) { // Facebook Exception looking up event; probably deleted, should mirror here. $event->delete(); } } foreach (User::where('unsubscribed_email', 'no') as $user) { $this->dispatch(new SendEmail($user)); } }
public function post($account = null) { FacebookSession::setDefaultApplication(getenv('EVC_FACEBOOK_APP_ID'), getenv('EVC_FACEBOOK_APP_SECRET')); $client = new Client(); $client->setDefaultOption('verify', false); $res = $client->get('https://graph.facebook.com/v2.2/oauth/access_token', ['query' => ['client_id' => getenv('EVC_FACEBOOK_APP_ID'), 'client_secret' => getenv('EVC_FACEBOOK_APP_SECRET'), 'grant_type' => 'client_credentials']]); $access_token = substr($res->getBody(), 13); // var_dump($access_token); // die(); $session = new FacebookSession($access_token); // Get the GraphUser object for the current user: // try { // $graphObject = (new FacebookRequest($session, 'GET', '/me/accounts'))->execute()->getGraphObject(); // $graphObject = (new FacebookRequest( // $session, 'GET', '/' . getenv("EVC_FACEBOOK_APP_ID") // ))->execute()->getGraphObject(); // $graphObject = (new FacebookRequest( // $session, 'POST', '/' . getenv("EVC_FACEBOOK_PAGE_ID") . '/feed', array( // // 'link' => '', // 'message' => 'President Goodluck Jonathan hosted the eight presidential media chat, since May 2011, talks on Security, Elections and debunks rumours #EVC' // ) // ))->execute()->getGraphObject(GraphPage::className()); var_dump($graphObject); // } // catch (FacebookRequestException $e) {} // catch (\Exception $e) {} }
/** * @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']); } }
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); }
public function __construct() { $this->ci =& get_instance(); FacebookSession::setDefaultApplication($this->ci->config->item('api_id', 'facebook'), $this->ci->config->item('app_secret', 'facebook')); $this->helper = new FacebookRedirectLoginHelper($this->ci->config->item('redirect_url', 'facebook')); if ($this->ci->session->userdata('fb_token')) { $this->session = new FacebookSession($this->ci->session->userdata('fb_token')); // Validate the access_token to make sure it's still valid try { if (!$this->session->validate()) { $this->session = false; } } catch (Exception $e) { // Catch any exceptions $this->session = false; } } else { try { $this->session = $this->helper->getSessionFromRedirect(); } catch (FacebookRequestException $ex) { // When Facebook returns an error } catch (\Exception $ex) { // When validation fails or other local issues } } if ($this->session) { $this->ci->session->set_userdata('fb_token', $this->session->getToken()); $this->session = new FacebookSession($this->session->getToken()); } }
private function create_fb_session() { // Facebook app config FacebookSession::setDefaultApplication($this->app_id, $this->app_secret); // Facebook session login $this->fb_session = new FacebookSession($this->access_token); }
/** * This function runs the script * @param $name string * @param $args array | null */ public function run($name, $args) { if ($name != Website::WEBSITE_SCRIPT_TYPE_PRESCRIPT) { return; } $credentials = $this->backendContainer->getConfigInstance()->getFacebookAppCredentials(); if (($id = $credentials['id']) == "" || ($secret = $credentials['secret']) == "" || !isset($this->backendContainer->getConfigInstance()['facebook_page_id'])) { return; } FacebookSession::setDefaultApplication($id, $secret); $this->backendContainer->facebookPage = function (BackendSingletonContainer $container) { return new FacebookPageImpl($container, $this->backendContainer->getConfigInstance()['facebook_page_id']); }; $vars = $this->backendContainer->getSiteInstance()->getVariables(); $k = 'FacebookSessionInitializePreScriptImpl_last_updated'; if ($vars->hasKey($k) && $vars->getValue($k) > time() - 86400) { return; } $vars->setValue($k, time()); /** @var FacebookPage $fb */ $fb = $this->backendContainer->facebookPage; if ($fb->update()) { $this->backendContainer->getSiteInstance()->modify(); } }
/** * @return \Facebook\FacebookSession */ public function getSession() { $conf = json_decode(file_get_contents(realpath(dirname(__FILE__)) . '/config.json')); Api::init($conf->applicationId, $conf->applicationSecret, $conf->accessToken); FacebookSession::setDefaultApplication($conf->applicationId, $conf->applicationSecret); return new FacebookSession($conf->accessToken); }
public function action_index() { $gameList = DB::query(Database::SELECT, "SELECT * FROM game")->execute(); $this->template->content = $gameList[0]['name']; require_once Kohana::find_file('vendor', 'vendor/autoload'); $config = Kohana::$config->load('auth'); //$session = Session::instance($config['session_type']); FacebookSession::setDefaultApplication('376812619137510', 'd054fff7f6146da72c9585d78d0357b5'); $helper = new FacebookJavaScriptLoginHelper(); try { $session = $helper->getSession(); } catch (FacebookRequestException $ex) { // When Facebook returns an error $this->template->content = "fb returned an error"; } catch (\Exception $ex) { // When validation fails or other local issues $this->template->content = "validation failed"; //print_r($ex); } if (isset($session)) { $request = new FacebookRequest($session, 'GET', '/me'); $response = $request->execute(); $graphObject = $response->getGraphObject(); if (isset($graphObject->id)) { $loginData = array('first_name' => $graphObject->first_name); } $this->template->content = "Hi, " . $graphObject->getProperty('first_name'); } else { echo "No session"; } }
/** * @return FacebookRedirectLoginHelper */ protected function getFacebookRedirectLoginHelper() { FacebookSession::setDefaultApplication($this->appId, $this->appSecret); $helper = new FacebookRedirectLoginHelper($this->getRedirectUrl()); $helper->disableSessionStatusCheck(); return $helper; }
public function register($kernel, $options = array()) { FacebookSession::setDefaultApplication($options['AppId'], $options['AppSecret']); $kernel->facebookSession = function () use($options) { return FacebookSession::newAppSession(); }; }
protected function initialize() { if (!$this->loaded) { FacebookSession::setDefaultApplication(Config::get('accounts.facebook.id'), Config::get('accounts.facebook.secret')); $this->loaded = true; } }
/** * @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'); }
public function __construct() { // Load config $this->load->config('facebook'); // Load required libraries and helpers $this->load->library('session'); $this->load->helper('url'); // App id and secret $app_id = $this->config->item('facebook_app_id'); $app_secret = $this->config->item('facebook_app_secret'); // Initiate the Facebook SDK FacebookSession::setDefaultApplication($app_id, $app_secret); // Load correct helper depending or login type // that is set in the config if ($this->config->item('facebook_login_type') == 'js') { // Javascript helper $this->helper = new FacebookJavaScriptLoginHelper(); } else { if ($this->config->item('facebook_login_type') == 'canvas') { // Canvas helper $this->helper = new FacebookCanvasLoginHelper(); } else { if ($this->config->item('facebook_login_type') == 'web') { // Web helper (redirect) $this->helper = new FacebookRedirectLoginHelper(base_url() . $this->config->item('facebook_login_redirect_url')); } } } // Create session right away if we have one $this->facebook_session(); }
public function BuildLink($params = null) { require_once 'Facebook/FacebookSDKException.php'; $APP_ID = $this->GetClientId(); $APP_SECRET = $this->GetClientSecret(); if (!isset($APP_ID) || !isset($APP_SECRET)) { throw new \Facebook\FacebookSDKException('You must to set the app client credentials'); } require_once 'Facebook/FacebookSession.php'; \Facebook\FacebookSession::setDefaultApplication($APP_ID, $APP_SECRET); $CALLBACK_URL = $this->GetCallbackUrl(); if (!isset($CALLBACK_URL)) { throw new \Facebook\FacebookSDKException('You must to set callback url'); } $SCOPE = $this->GetScope(); if (!isset($SCOPE)) { throw new \Facebook\FacebookSDKException('You must to set scope'); } require_once 'Facebook/FacebookRequest.php'; require_once 'Facebook/FacebookRedirectLoginHelper.php'; $helper = new \Facebook\FacebookRedirectLoginHelper($CALLBACK_URL); $STATE = $this->GetState(); if (isset($STATE)) { $helper->SetState($STATE); } $redirectUrl = $helper->getLoginUrl($SCOPE); // var_dump($redirectUrl); return $redirectUrl; }
public function loginFacebookAction() { $response = array("status" => 0, "message" => "Thao tác không thành công"); if (!empty($this->user)) { $response["status"] = 1; } else { if ($this->request->isPost()) { $acesstoken = $this->request->getPost("accesstoken", null, false); \Facebook\FacebookSession::setDefaultApplication($this->config["FACEBOOK_ID"], $this->config["FACEBOOK_SECRET"]); $session = new \Facebook\FacebookSession($acesstoken); if ($session) { $user_profile = (new \Facebook\FacebookRequest($session, 'GET', '/me', ['fields' => 'id,name,email']))->execute()->getGraphObject(\Facebook\GraphUser::className()); if (!empty($user_profile)) { $email = $user_profile->getEmail(); $id = $user_profile->getId(); $username = explode("@", $email); $username = $username[0] . "_fb_" . $id; $data_user = array("email" => $email, "nickname" => $user_profile->getName(), "username" => $username, "id" => $id); $response = $this->doSocialLogin($data_user); } } } } echo json_encode($response); exit; }
function __construct() { $this->fb_app_id = FB_APP_ID; $this->fb_app_secret = FB_APP_SECRET; FacebookSession::setDefaultApplication($this->fb_app_id, $this->fb_app_secret); $this->set_session(); }
public static function user() { if (self::$user !== false) { return self::$user; } FacebookSession::setDefaultApplication(\Config::get('fb-auth::config.facebook_app_id'), \Config::get('fb-auth::config.facebook_secret')); $token = \Input::get('accessToken'); if (!$token) { $token = \Request::header('FB-Access-Token'); } if (!$token) { self::$user = null; return null; } $session = new FacebookSession($token); try { $me = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className()); self::$user = \User::from_fb($me); } catch (FacebookAuthorizationException $e) { self::$user = null; } catch (FacebookRequestException $e) { self::$user = null; } catch (\Exception $e) { self::$user = null; } return self::$user; }
function __construct() { parent::__construct(); $this->load->helper('form'); $this->load->library('form_validation'); $this->load->library('session'); $this->load->library('email'); $this->load->helper('url'); $this->load->helper('cookie'); $this->load->model('user_model'); $this->load->model('user_cookie_model'); // setting up email =============================================== $config['useragent'] = "Codeigniter"; $config['protocol'] = "smtp"; $config['smtp_host'] = "smtp.gmail.com"; $config['smtp_port'] = "465"; $config['smtp_user'] = "******"; $config['smtp_pass'] = "******"; $config['charset'] = "utf-8"; $config['mailtype'] = "html"; $config['newline'] = "\r\n"; $config['smtp_crypto'] = "ssl"; $this->email->initialize($config); $this->email->from('*****@*****.**', 'VN UP TEST'); // ================================================================== $this->default_redirectURL = config_item('base_url') . 'user/user'; FacebookSession::setDefaultApplication($this->app_id, $this->app_secret); $this->helper = new FacebookRedirectLoginHelper($this->default_redirectURL); $this->wp_hasher = new PasswordHash(8, true); }
/** * Create a new FacebookInsights instance. * * @param \Illuminate\Config\Repository $config */ public function __construct(Repository $config) { $this->config = $config; $this->pageId = $this->config->get('facebook-insights::page-id'); FacebookSession::setDefaultApplication($this->config->get('facebook-insights::app-id'), $this->config->get('facebook-insights::app-secret')); $this->session[$this->pageId] = new FacebookSession($this->config->get('facebook-insights::access-token')); }
/** * Constructor for Connect Library */ public function __construct($client, $scope) { $this->scopes = $scope; $this->client = $client; $this->sentry = \App::make('sentry'); $config = Config::get('connect::facebook.clients.' . $client); FacebookSession::setDefaultApplication($config['client_id'], $config['client_secret']); }
/** * When creating an instance it will create also a FacebookSession for further usage * @param integer $apiKey * @param string $appSecret * @param string $appAccessToken */ public function __construct($apiKey, $appSecret, $appAccessToken) { $this->apiKey = $apiKey; $this->appSecret = $appSecret; $this->appAccessToken = $appAccessToken; FacebookSession::setDefaultApplication($this->apiKey, $this->appSecret); $this->facebookSession = new FacebookSession($this->appAccessToken); }
/** * @param Store $session * @param Redirector $redirect * @param Repository $config * @param null $appId * @param null $appSecret */ public function __construct($appId = null, $appSecret = null, $redirect_url = null) { session_start(); $this->appId = $appId; $this->appSecret = $appSecret; $this->redirect_url = $redirect_url; FacebookSession::setDefaultApplication($appId, $appSecret); }
public function __construct($di) { $this->di = $di; $fbConfig = $di->get('config')->pup->connectors->facebook; $protocol = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://'; $this->url = $protocol . $_SERVER['HTTP_HOST'] . '/user/loginWithFacebook'; FacebookSession::setDefaultApplication($fbConfig->appId, $fbConfig->secret); }
public function __construct(array $options) { if (empty($options['clientId']) || empty($options['clientSecret'])) { throw new \InvalidArgumentException("\$options['clientId'] and \$options['clientSecret'] need to be set"); } \Facebook\FacebookSession::setDefaultApplication($options['clientId'], $options['clientSecret']); $this->service = new \Facebook\FacebookJavaScriptLoginHelper(); }
function __construct() { FacebookSession::setDefaultApplication('979326508760258', 'bb0df924a97fceeff431414965a31888'); // FacebookSession::setDefaultApplication('135647529897166', 'd9bbd5df5449e66437d2a3933e5bad39'); // $this->helper = new FacebookRedirectLoginHelper("http://localhost/wp/wp-admin/options-general.php?page=social-fetcher-options"); $this->helper = new FacebookRedirectLoginHelper("http://rodon.bravomotorcompany.com.ar/wp-admin/options-general.php?page=social-fetcher-options"); $this->checkIfNewSession(); }
public function __construct($appId, $appSecret, $callbackUrl, $pageUrl) { $this->appId = $appId; $this->appSecret = $appSecret; $this->callbackUrl = $callbackUrl; $this->pageUrl = $pageUrl; FacebookSession::setDefaultApplication($appId, $appSecret); }
/** * @param $appId Facebook Application ID * @param $appSecret Facebook Application secret */ public function __construct($appId, $appSecret, $redirectUrl = null, $scope = array()) { $this->appId = $appId; $this->appSecret = $appSecret; $this->scope = $scope; $this->redirectUrl = $redirectUrl; FacebookSession::setDefaultApplication($this->appId, $this->appSecret); }
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; }