本文整理汇总了PHP中Facebook\FacebookSession::newAppSession方法的典型用法代码示例。如果您正苦于以下问题:PHP FacebookSession::newAppSession方法的具体用法?PHP FacebookSession::newAppSession怎么用?PHP FacebookSession::newAppSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\FacebookSession
的用法示例。
在下文中一共展示了FacebookSession::newAppSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSession
/**
* @return FacebookSession
*/
protected function getSession()
{
if (!$this->session) {
$this->session = FacebookSession::newAppSession();
}
return $this->session;
}
示例2: end
/**
* Returns the URL to send the user in order to log out of Facebook.
* @return string|bool The url to log out
*/
public function end()
{
if (is_null($this->fbsession)) {
return false;
}
return $this->fbsession->getFacebookLoginHelperInstance()->getLogoutUrl(FacebookSession::newAppSession(), "/");
}
示例3: register
public function register($kernel, $options = array())
{
FacebookSession::setDefaultApplication($options['AppId'], $options['AppSecret']);
$kernel->facebookSession = function () use($options) {
return FacebookSession::newAppSession();
};
}
示例4: 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));
}
}
示例5: getAppSession
public function getAppSession()
{
if ($this->appSession) {
return $this->appSession;
}
return $this->appSession = FacebookSession::newAppSession();
}
示例6: __construct
public function __construct($config, $logCallback = null)
{
if (is_callable($logCallback)) {
$this->logCallback = $logCallback;
}
FacebookSession::setDefaultApplication($config['app_id'], $config['secret']);
$this->appSession = FacebookSession::newAppSession($config['app_id'], $config['secret']);
$this->appId = $config['app_id'];
}
示例7: testAppSessionValidates
public function testAppSessionValidates()
{
$session = FacebookSession::newAppSession();
try {
$session->validate();
} catch (\Facebook\FacebookSDKException $ex) {
$this->fail('Exception thrown validating app session.');
}
}
示例8: __construct
/**
* @param string $appId
* @param string $appSecret
*
* @throws Exception\FacebookSessionException
*/
public function __construct($appId, $appSecret)
{
FacebookSession::setDefaultApplication($appId, $appSecret);
$session = FacebookSession::newAppSession();
if (!$session) {
throw new FacebookSessionException(sprintf('\\C2iS\\SocialWall\\Facebook\\FacebookManager needs a valid facebook session in order to make FB API calls. Check your informations for App ID "%s"', $appId));
}
$this->session = $session;
}
示例9: _getChannelV4
private static function _getChannelV4($channel)
{
FacebookSession::setDefaultApplication(self::FACEBOOK_APP_ID, self::FACEBOOK_SECRET_KEY);
$session = FacebookSession::newAppSession(self::FACEBOOK_APP_ID, self::FACEBOOK_SECRET_KEY);
$request = new FacebookRequest($session, 'GET', '/' . $channel . '/posts?fields=type,created_time,message,picture,object_id,link');
$response = $request->execute();
$graphObject = $response->getGraphObject();
return $graphObject->getPropertyAsArray('data');
}
示例10: build
public function build()
{
if ($this->accessToken != null) {
$session = new FacebookSession($this->accessToken);
} else {
$session = FacebookSession::newAppSession();
}
return $session;
}
示例11: example
public function example()
{
$application = FacebookSession::setDefaultApplication($this->config['app_id'], $this->config['app_secret']);
$session = FacebookSession::newAppSession();
$request = new FacebookRequest($session, 'GET', '/780788985274738');
$response = $request->execute();
$graphObject = $response->getGraphObject();
$response = $this->app->json($graphObject->asArray(), 200);
return $response;
}
示例12: getAccessToken
/**
* @param $code
* @return null
* @throws \Facebook\FacebookRequestException
* @throws \Facebook\FacebookSDKException
*/
protected function getAccessToken($code)
{
$response = (new FacebookRequest(FacebookSession::newAppSession(), 'GET', '/oauth/access_token', ['client_id' => FacebookSession::_getTargetAppId(), 'client_secret' => FacebookSession::_getTargetAppSecret(), 'redirect_uri' => Config::get('auth.providers.facebook.redirect_uri'), 'code' => $code]))->execute()->getResponse();
// Graph v2.3 and greater return objects on the /oauth/access_token endpoint
$accessToken = null;
if (is_object($response) && isset($response->access_token)) {
$accessToken = $response->access_token;
} elseif (is_array($response) && isset($response['access_token'])) {
$accessToken = $response['access_token'];
}
return $accessToken;
}
示例13: getSession
private static function getSession()
{
FacebookSession::setDefaultApplication('852604174797487', '9e20b12fb740a2f5f58287f4378d23b0');
$session = FacebookSession::newAppSession();
try {
$session->validate();
return $session;
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
echo $ex->getMessage();
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
echo $ex->getMessage();
}
}
示例14: init
/**
* Let's get started
*/
protected function init()
{
// security - ensure we only run these scripts under CLI
$this->requireCLI();
parent::init();
$this->fb = FacebookSession::newAppSession();
try {
$this->fb->validate();
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
error_log($ex->getMessage());
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
error_log($ex->getMessage());
}
}
示例15: __construct
public function __construct()
{
$this->ci =& get_instance();
$this->permissions = $this->ci->config->item('permissions', 'facebook');
// Initialize the SDK
FacebookSession::setDefaultApplication($this->ci->config->item('api_id', 'facebook'), $this->ci->config->item('app_secret', 'facebook'));
$this->session = FacebookSession::newAppSession();
// Create the login helper and replace REDIRECT_URI with your URL
// Use the same domain you set for the apps 'App Domains'
// e.g. $helper = new FacebookRedirectLoginHelper( 'http://mydomain.com/redirect' );
//$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 = null;
}
} catch ( Exception $e ) {
// Catch any exceptions
$this->session = null;
}
} else {
// No session exists
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() );
}*/
}