本文整理汇总了PHP中Facebook\Facebook::getRedirectLoginHelper方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::getRedirectLoginHelper方法的具体用法?PHP Facebook::getRedirectLoginHelper怎么用?PHP Facebook::getRedirectLoginHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\Facebook
的用法示例。
在下文中一共展示了Facebook::getRedirectLoginHelper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginFinish
/**
* {@inheritdoc}
*/
function loginFinish()
{
$helper = $this->api->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch (Facebook\Exceptions\FacebookResponseException $e) {
throw new Hybrid_Exception('Facebook Graph returned an error: ' . $e->getMessage());
} catch (Facebook\Exceptions\FacebookSDKException $e) {
throw new Hybrid_Exception('Facebook SDK returned an error: ' . $e->getMessage());
}
if (!isset($accessToken)) {
if ($helper->getError()) {
throw new Hybrid_Exception(sprintf("Could not authorize user, reason: %s (%d)", $helper->getErrorDescription(), $helper->getErrorCode()));
} else {
throw new Hybrid_Exception("Could not authorize user. Bad request");
}
}
try {
// Validate token
$oAuth2Client = $this->api->getOAuth2Client();
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
$tokenMetadata->validateAppId($this->config["keys"]["id"]);
$tokenMetadata->validateExpiration();
// Exchanges a short-lived access token for a long-lived one
if (!$accessToken->isLongLived()) {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
}
} catch (FacebookSDKException $e) {
throw new Hybrid_Exception($e->getMessage(), 0, $e);
}
$this->setUserConnected();
$this->token("access_token", $accessToken->getValue());
}
示例2: _getAccessToken
/**
* @return bool|\Facebook\Authentication\AccessToken|null
* @throws Exceptions\FacebookSDKException
*/
protected function _getAccessToken()
{
$redirectLoginHelper = $this->_facebook->getRedirectLoginHelper();
try {
$accessToken = $redirectLoginHelper->getAccessToken();
} catch (FacebookResponseException $e) {
CakeLog::write('AuthManager', 'Graph returned an error: ' . $e->getMessage());
return false;
} catch (FacebookSDKException $e) {
CakeLog::write('AuthManager', 'Facebook SDK returned an error: ' . $e->getMessage());
return false;
}
$oAuth2Client = $this->_facebook->getOAuth2Client();
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
try {
$tokenMetadata->validateAppId(Configure::read('FacebookAds.app_id'));
$tokenMetadata->validateExpiration();
} catch (FacebookSDKException $e) {
CakeLog::write('AuthManager', 'Facebook SDK returned an error: ' . $e->getMessage());
return false;
}
if (!$accessToken->isLongLived()) {
try {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
} catch (FacebookSDKException $e) {
CakeLog::write('AuthManager', 'Error getting long-lived access token: ' . $e->getMessage());
return false;
}
}
return $accessToken;
}
示例3: getAccessTokenFromRedirect
public function getAccessTokenFromRedirect()
{
try {
$token = $this->facebook->getRedirectLoginHelper()->getAccessToken();
return $token;
} catch (\Exception $e) {
abort(500);
}
}
示例4: __construct
public function __construct($appId, $appSecret, PersistentDataInterface $persistentDataHandler, Router $router, Registry $doctrine, $tokenStorage, $adminId)
{
$this->router = $router;
$this->doctrine = $doctrine;
$this->tokenStorage = $tokenStorage;
$this->adminId = $adminId;
$this->facebook = new Facebook(['app_id' => $appId, 'app_secret' => $appSecret, 'default_graph_version' => 'v2.4', 'persistent_data_handler' => $persistentDataHandler]);
$this->helper = $this->facebook->getRedirectLoginHelper();
}
示例5: __construct
/**
* @param $params array - data from config.neon
* @param $cookieName String cookie name
* @param Nette\Http\Response $httpResponse
* @param Nette\Http\Request $httpRequest
*/
public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest)
{
$this->params = $params;
$this->cookieName = $cookieName;
$this->httpResponse = $httpResponse;
$this->httpRequest = $httpRequest;
$this->callBackUrl = $this->params["callbackURL"];
$this->fb = new Facebook\Facebook(['app_id' => $this->params["appId"], 'app_secret' => $this->params["appSecret"], 'default_graph_version' => 'v2.5']);
$this->helper = $this->fb->getRedirectLoginHelper();
}
示例6: __construct
public function __construct($container, $em, $session)
{
$this->container = $container;
$this->em = $em;
$this->session = $session;
$app_id = $this->container->getParameter('kvk_scraper.facebook.app_id');
$app_secret = $this->container->getParameter('kvk_scraper.facebook.secret');
$this->fb = new Facebook(['app_id' => $app_id, 'app_secret' => $app_secret, 'default_graph_version' => 'v2.5']);
$this->fb->setDefaultAccessToken(implode('|', [$app_id, $app_secret]));
$this->fb_helper = $this->fb->getRedirectLoginHelper();
}
示例7: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$fb = new Facebook(['app_id' => env('FACEBOOK_APP_ID'), 'app_secret' => env('FACEBOOK_APP_SECRET'), 'default_graph_version' => 'v2.5']);
$helper = $fb->getRedirectLoginHelper();
try {
if (isset($_SESSION['facebook_access_token'])) {
$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)) {
$_SESSION['facebook_access_token'] = (string) $accessToken;
return $next($request);
}
$permissions = ['public_profile', 'publish_actions'];
$loginUrl = $helper->getLoginUrl(env('CALLBACK'), $permissions);
return redirect($loginUrl);
}
示例8: callback
public function callback()
{
$fb = new Facebook(['app_id' => Config::get('facebook.app_id'), 'app_secret' => Config::get('facebook.app_secret'), 'default_graph_version' => Config::get('facebook.default_graph_version'), 'persistent_data_handler' => Config::get('facebook.persistent_data_handler')]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
return Redirect::to('/')->with('mensaje', 'Graph returned an error: ' . $e->getMessage());
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
return Redirect::to('/')->with('mensaje', 'Facebook SDK returned an error: ' . $e->getMessage());
exit;
}
if (!isset($accessToken)) {
if ($helper->getError()) {
header('HTTP/1.0 401 Unauthorized');
echo "Error: " . $helper->getError() . "\n";
echo "Error Code: " . $helper->getErrorCode() . "\n";
echo "Error Reason: " . $helper->getErrorReason() . "\n";
echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'Bad request';
}
exit;
}
// Logged in
//echo '<h3>Access Token</h3>';
//var_dump($accessToken->getValue());
// The OAuth 2.0 client handler helps us manage access tokens
$oAuth2Client = $fb->getOAuth2Client();
// Get the access token metadata from /debug_token
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
//echo '<h3>Metadata</h3>';
//var_dump($tokenMetadata);
// Validation (these will throw FacebookSDKException's when they fail)
$tokenMetadata->validateAppId(Config::get('facebook.app_id'));
// If you know the user ID this access token belongs to, you can validate it here
//$tokenMetadata->validateUserId('123');
$tokenMetadata->validateExpiration();
if (!$accessToken->isLongLived()) {
// Exchanges a short-lived access token for a long-lived one
try {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
} catch (Facebook\Exceptions\FacebookSDKException $e) {
return Redirect::to('/')->with('mensaje', "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>\n\n");
exit;
}
//echo '<h3>Long-lived</h3>';
//var_dump($accessToken->getValue());
}
Session::put('fb_access_token', (string) $accessToken);
// User is logged in with a long-lived access token.
// You can redirect them to a members-only page.
return Redirect::to('/')->with('mensaje', 'Ya puede publicar');
}
示例9: indexAction
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$this->get('session')->start();
$config = ['app_id' => '1690300947880602', 'app_secret' => '0b6107ea187ee9cd79adc66a2dd84254', 'default_graph_version' => 'v2.5', 'persistent_data_handler' => 'session'];
$fb = new Facebook\Facebook($config);
$helper = $fb->getRedirectLoginHelper();
try {
$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 ($helper->getError()) {
header('HTTP/1.0 401 Unauthorized');
echo "Error: " . $helper->getError() . "\n";
echo "Error Code: " . $helper->getErrorCode() . "\n";
echo "Error Reason: " . $helper->getErrorReason() . "\n";
echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'Bad request';
}
exit;
}
// Logged in
echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());
// The OAuth 2.0 client handler helps us manage access tokens
$oAuth2Client = $fb->getOAuth2Client();
// Get the access token metadata from /debug_token
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
echo '<h3>Metadata</h3>';
var_dump($tokenMetadata);
// Validation (these will throw FacebookSDKException's when they fail)
$tokenMetadata->validateAppId($config['app_id']);
// If you know the user ID this access token belongs to, you can validate it here
//$tokenMetadata->validateUserId('123');
$tokenMetadata->validateExpiration();
if (!$accessToken->isLongLived()) {
// Exchanges a short-lived access token for a long-lived one
try {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>\n\n";
exit;
}
echo '<h3>Long-lived</h3>';
var_dump($accessToken->getValue());
}
return new Response();
}
示例10: loginAction
/**
* @Route("/login", name="login")
*/
public function loginAction(Request $request)
{
$this->get('session')->start();
$fb = new Facebook(['app_id' => '1690300947880602', 'app_secret' => '0b6107ea187ee9cd79adc66a2dd84254', 'default_graph_version' => 'v2.5', 'persistent_data_handler' => 'session']);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email'];
// Optional permissions
$loginUrl = $helper->getLoginUrl($this->generateUrl('homepage', array(), true), $permissions);
return $this->render('login/login.html.twig', array("loginUrl" => $loginUrl));
}
示例11: callback
public function callback()
{
$app_id = env('FACEBOOK_APP_ID');
$app_secret = env('FACEBOOK_APP_SECRET');
$app_graph = env('default_graph_version');
$fb = new Facebook(['app_id' => $app_id, 'app_secret' => $app_secret, 'default_graph_version' => $app_graph, 'default_access_token' => '903539709730443|d46fd1d4d733eda0600f3f29b1d818eb']);
$helper = $fb->getRedirectLoginHelper();
$token = $helper->getAccessToken();
//echo $token;
}
示例12: loginCallback
public function loginCallback()
{
$fb = new Facebook(['app_id' => '709854915792963', 'app_secret' => '74e61a2eaf730835d8b4b39ec3aede8e', 'default_graph_version' => 'v2.2']);
$helper = $fb->getRedirectLoginHelper();
try {
$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)) {
// Logged in!
$access_token = (string) $accessToken;
// Now you can redirect to another page and use the
// access token from $_SESSION['facebook_access_token']
}
$response = $fb->get('/me?fields=id,name,email', $access_token);
$me = $response->getGraphUser();
$uid = $me['id'];
//return $uid;
if ($uid == 0) {
return Redirect::to('/')->with('message', 'There was an error');
}
//return $user;
$profile = App\Profile::whereUid($uid)->first();
//if user does not exist create user
if (empty($profile)) {
$user = new App\User();
$existinguser = App\User::whereemail($me['email'])->first();
if (empty($existinguser)) {
$user->name = $me['name'];
$user->email = $me['email'];
//$user->uid=$uid;
$user->save();
}
$profile = new App\Profile();
$profile->photo = 'https://graph.facebook.com/' . $me['id'] . '/picture?type=large';
$user->email = $me['email'];
$profile->uid = $uid;
$profile->username = $me['name'];
$profile = $user->profiles()->save($profile);
}
//else only update his access token
$profile->access_token = $access_token;
$profile->save();
$user = $profile->users;
//login the user
Auth::login($user);
return Redirect::to('/dashboard');
}
示例13: loginAction
/**
* @Route("/login", name="fb_login")
* @param Request $request
* @return Response
*/
public function loginAction(Request $request)
{
$fb = new Facebook(['app_id' => self::APP_ID, 'app_secret' => self::APP_SECRET]);
$helper = $fb->getRedirectLoginHelper();
$access_token = $this->get('session')->get('facebook_access_token');
if (!$access_token) {
$access_token = (string) $helper->getAccessToken();
if ($access_token) {
$this->get('session')->set('facebook_access_token', $access_token);
}
}
$destUrl = $this->generateUrl('fb_login', [], UrlGeneratorInterface::ABSOLUTE_URL);
$loginUrl = $helper->getLoginUrl($destUrl, ['ads_management', 'manage_pages', 'publish_pages']);
return $this->render('AppBundle:AdWords:facebook_login.html.twig', array('loginUrl' => $loginUrl, 'destUrl' => $destUrl, 'appId' => self::APP_ID));
}
示例14: facebook
public function facebook()
{
$fb = new Facebook\Facebook(['app_id' => Config::get('facebook.appid'), 'app_secret' => Config::get('facebook.secret'), 'default_graph_version' => 'v2.2']);
$helper = $fb->getRedirectLoginHelper();
try {
$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;
}
$loginUrl = $helper->getLoginUrl('http://localhost:8000/home');
$_SESSION['login_type'] = "facebook";
return redirect($loginUrl);
}
示例15: fbcallback
public function fbcallback()
{
//Initialize facebook api
$fb = new Facebook(['app_id' => self::FB_APP_ID, 'app_secret' => self::FB_APP_SECRET, 'default_graph_version' => self::FB_APP_VERSION]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch (Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
// Logged in!
$fb->setDefaultAccessToken($accessToken);
try {
$response = $fb->get('/me?locale=en_US&fields=name,email,gender,age_range,picture,first_name,last_name,middle_name,birthday,hometown');
$userNode = $response->getGraphUser();
} catch (Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$this->loadComponent('GeoIP');
$pictureUser = $userNode->getPicture()->asArray();
$userNode = array('type' => 0, 'status' => 1, 'password' => str_replace(' ', '', strtolower($userNode->getName())), 'email' => $userNode->getEmail(), 'full_name' => $userNode->getName(), 'gender' => $userNode->getGender(), 'image' => $pictureUser['url'], 'birthday' => $userNode->getBirthday(), 'address' => $userNode->getHometown(), 'facebook' => 'https://www.facebook.com/' . $userNode->getId());
// Now you can redirect to another page and use the
$this->request->session()->write('fb_user', $userNode);
$this->redirect('/users/register');
}
}