本文整理汇总了PHP中Facebook\FacebookSession::setDefaultApplication方法的典型用法代码示例。如果您正苦于以下问题:PHP FacebookSession::setDefaultApplication方法的具体用法?PHP FacebookSession::setDefaultApplication怎么用?PHP FacebookSession::setDefaultApplication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\FacebookSession
的用法示例。
在下文中一共展示了FacebookSession::setDefaultApplication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: handle
/**
* 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));
}
}
示例3: post
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) {}
}
示例4: 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']);
}
}
示例5: 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);
}
示例6: __construct
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());
}
}
示例7: create_fb_session
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);
}
示例8: run
/**
* 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();
}
}
示例9: getSession
/**
* @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);
}
示例10: action_index
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";
}
}
示例11: getFacebookRedirectLoginHelper
/**
* @return FacebookRedirectLoginHelper
*/
protected function getFacebookRedirectLoginHelper()
{
FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
$helper = new FacebookRedirectLoginHelper($this->getRedirectUrl());
$helper->disableSessionStatusCheck();
return $helper;
}
示例12: register
public function register($kernel, $options = array())
{
FacebookSession::setDefaultApplication($options['AppId'], $options['AppSecret']);
$kernel->facebookSession = function () use($options) {
return FacebookSession::newAppSession();
};
}
示例13: initialize
protected function initialize()
{
if (!$this->loaded) {
FacebookSession::setDefaultApplication(Config::get('accounts.facebook.id'), Config::get('accounts.facebook.secret'));
$this->loaded = true;
}
}
示例14: 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');
}
示例15: __construct
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();
}