本文整理汇总了PHP中Facebook\Facebook::getLoginUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::getLoginUrl方法的具体用法?PHP Facebook::getLoginUrl怎么用?PHP Facebook::getLoginUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\Facebook
的用法示例。
在下文中一共展示了Facebook::getLoginUrl方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$statusUrl = $facebook->getLoginStatusUrl();
$loginUrl = $facebook->getLoginUrl();
}
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
示例2: renderLogin
/**
* Generate and print the rendered login markup to STDOUT.
*
* @param array $form_options
*
* @return void
*/
public function renderLogin($form_options = [])
{
if (!FACEBOOK_APP_ID) {
echo 'Please configure Facebook with your APP_ID.';
return;
}
if (!FACEBOOK_APP_SECRET) {
echo 'Please configure Facebook with your APP_SECRET.';
return;
}
$facebook = new \Facebook(['appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET]);
// User was already logged in.
try {
$user = $facebook->getUser();
if ($user) {
$user_profile = $facebook->api('/me');
$facebooklink = false;
} else {
$facebooklink = $facebook->getLoginUrl();
}
} catch (\Exception $c) {
$facebooklink = $facebook->getLoginUrl();
}
// $logoutUrl = $facebook->getLogoutUrl();
$tpl = \Core\Templates\Template::Factory('includes/user/facebook_login.tpl');
$tpl->assign('facebooklink', $facebooklink);
$tpl->render();
}
示例3: login
public function login()
{
$facebook = new Facebook(\Config::get('facebook'));
$params = array('redirect_uri' => url('/login/fb/callback'), 'scope' => 'email');
return \Redirect::to($facebook->getLoginUrl($params));
}
示例4: path
<?php
use App\Classes\User;
use App\Libs\Statics\Func;
use App\Models\GoogleModel;
use Carbon\Carbon;
use Facebook\Facebook;
return ['config' => ['cache' => path('resources.cache'), 'debug' => true], 'static_functions' => ['Url', 'Session', 'Token'], 'callable_functions' => ['social' => function ($c) {
switch ($c) {
case 'f':
$url = new Facebook();
return $url->getLoginUrl();
case 'g':
$client = new Google_Client();
$auth = new GoogleModel($client);
return $auth->getAuthUrl();
}
}, 'is_loggedin' => function () {
$u = new User();
return $u->isLoggedIn();
}, 'time' => function ($time) {
$t = new Carbon($time);
return $t->toRfc850String();
}, 'readable_time' => function ($time) {
$t = new Carbon($time);
return $t->diffForHumans();
}, 'strip' => function ($string) {
// strip tags to avoid breaking any html
$string = strip_tags($string);
if (strlen($string) > 500) {
// truncate string
示例5: testGetLoginURLWithScopeParamsAsArray
public function testGetLoginURLWithScopeParamsAsArray()
{
$facebook = new Facebook(array('appId' => self::APP_ID, 'secret' => self::SECRET));
// fake the HPHP $_SERVER globals
$_SERVER['HTTP_HOST'] = 'www.test.com';
$_SERVER['REQUEST_URI'] = '/unit-tests.php';
$scope_params_as_array = array('email', 'sms', 'read_stream');
$extra_params = array('scope' => $scope_params_as_array, 'nonsense' => 'nonsense');
$login_url = parse_url($facebook->getLoginUrl($extra_params));
$this->assertEquals($login_url['scheme'], 'https');
$this->assertEquals($login_url['host'], 'www.facebook.com');
$this->assertEquals($login_url['path'], '/dialog/oauth');
// expect api to flatten array params to comma separated list
// should do the same here before asserting to make sure API is behaving
// correctly;
$extra_params['scope'] = implode(',', $scope_params_as_array);
$expected_login_params = array_merge(array('client_id' => self::APP_ID, 'redirect_uri' => 'http://www.test.com/unit-tests.php'), $extra_params);
$query_map = array();
parse_str($login_url['query'], $query_map);
$this->assertIsSubset($expected_login_params, $query_map);
// we don't know what the state is, but we know it's an md5 and should
// be 32 characters long.
$this->assertEquals(strlen($query_map['state']), $num_characters = 32);
}