本文整理汇总了PHP中Facebook\GraphUser::className方法的典型用法代码示例。如果您正苦于以下问题:PHP GraphUser::className方法的具体用法?PHP GraphUser::className怎么用?PHP GraphUser::className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\GraphUser
的用法示例。
在下文中一共展示了GraphUser::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginFacebookAction
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;
}
示例2: 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);
}
示例3: MeAction
public function MeAction($params)
{
$ACCESS_TOKEN = isset($params[self::AUTH_TOKEN]) ? $params[self::AUTH_TOKEN] : null;
$USER_ID = isset($params[self::USER_ID]) ? $params[self::USER_ID] : null;
// 1. If IS NOT set access token - get from DB by USER_ID
if (empty($ACCESS_TOKEN)) {
if (empty($USER_ID)) {
throw new FacebookSDKException('To get access token you need to supply USER_ID');
}
$params_social = array(\Av\MediaUserModel::MEDIA_ID => \Av\MediaModel::MEDIA_FACEBOOK, \Av\MediaUserModel::USER_ID => $USER_ID);
$oSocialUserMapper = new \Av\MediaUserModel();
$access_token_info = $oSocialUserMapper->GetCredentials($params_social);
$ACCESS_TOKEN = isset($access_token_info[\Av\MediaUserModel::ACCESS_TOKEN]) ? $access_token_info[\Av\MediaUserModel::ACCESS_TOKEN] : null;
if (empty($ACCESS_TOKEN)) {
throw new FacebookSDKException("No access token is saved for USER_ID {$USER_ID}");
}
}
$session = new FacebookSession($ACCESS_TOKEN);
try {
$fbRequest = new FacebookRequest($session, 'GET', '/me');
$user_profile = $fbRequest->execute()->getGraphObject(GraphUser::className());
$this->SetMediaUserId($user_profile->getId());
$this->SetUserEmail($user_profile->getEmail());
$this->SetName($user_profile->getName());
$this->SetVerified($user_profile->getVerified());
} catch (FacebookRequestException $e) {
echo __METHOD__ . __LINE__ . " Facebook error during authentication <br><pre>";
var_dump($e);
echo "</pre>";
return;
}
}
示例4: getCurrentSession
public function getCurrentSession()
{
$helper = new FacebookJavaScriptLoginHelper();
try {
if (!empty($_SESSION[self::SessionKey])) {
$accessToken = $_SESSION[self::SessionKey];
$_SESSION[self::SessionKey] = null;
$session = new \Facebook\FacebookSession($accessToken);
} else {
$session = $helper->getSession();
$accessToken = $session->getAccessToken();
$_SESSION[self::SessionKey] = (string) $accessToken;
}
} catch (\Exception $ex) {
Record::add(__CLASS__, $ex->getMessage(), $ex);
throw $ex;
}
if ($session) {
try {
$user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
return ['id' => $user_profile->getId(), 'name' => $user_profile->getName()];
} catch (FacebookRequestException $e) {
$error = "Exception occured, code: " . $e->getCode() . " with message: " . $e->getMessage();
Record::add(__CLASS__, $error, $e);
throw $e;
}
}
}
示例5: 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');
}
示例6: user
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;
}
示例7: connect
public function connect()
{
// check we have a valid session
$appId = Config::inst()->get('FacebookControllerExtension', 'app_id');
$secret = Config::inst()->get('FacebookControllerExtension', 'api_secret');
$session = $this->getFacebookHelper()->getSessionFromRedirect();
if ($session) {
$token = $session->getAccessToken();
// get a long lived token by default. Access token is saved in
// session.
try {
$long = $token->extend($appId, $secret);
if ($long) {
$accessTokenValue = (string) $long;
} else {
$accessTokenValue = (string) $token;
}
} catch (Exception $e) {
$accessTokenValue = (string) $token;
}
try {
Session::set(FacebookControllerExtension::FACEBOOK_ACCESS_TOKEN, $accessTokenValue);
$fields = Config::inst()->get('FacebookControllerExtension', 'facebook_fields');
$user = (new FacebookRequest($session, 'GET', '/me', array('fields' => implode(',', $fields))))->execute()->getGraphObject(GraphUser::className());
if (!($member = Member::currentUser())) {
// member is not currently logged into SilverStripe. Look up
// for a member with the UID which matches first.
$member = Member::get()->filter(array("FacebookUID" => $user->getId()))->first();
if (!$member) {
// see if we have a match based on email. From a
// security point of view, users have to confirm their
// email address in facebook so doing a match up is fine
$email = $user->getProperty('email');
if ($email) {
$member = Member::get()->filter(array('Email' => $email))->first();
}
}
if (!$member) {
$member = Injector::inst()->create('Member');
}
}
$member->syncFacebookDetails($user);
$member->logIn();
// redirect the user to the provided url, otherwise take them
// back to the route of the website.
if ($url = Session::get(FacebookControllerExtension::SESSION_REDIRECT_URL_FLAG)) {
return $this->redirect($url);
} else {
return $this->redirect(Director::absoluteBaseUrl());
}
} catch (Exception $e) {
SS_Log::log($e, SS_Log::ERR);
}
} else {
return $this->httpError(400);
}
return $this->httpError(400);
}
示例8: getUserProfile
public function getUserProfile()
{
try {
$user_profile = (new FacebookRequest($this->session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
return $user_profile;
} catch (FacebookRequestException $e) {
return false;
}
}
示例9: validateRequest
public function validateRequest(RequestInterface $request, ResponseInterface $response)
{
$identifier = $this->getQuerystringIdentifier();
if (!$request->request($identifier)) {
$response->setError(400, 'invalid_request', 'Missing parameters: "' . $identifier . '" required');
return null;
}
$fb_app_id = Config::get('api-foundation::fb_app_id');
$fb_app_secret = Config::get('api-foundation::fb_app_secret');
if (empty($fb_app_id)) {
throw new \LogicException('Facebook APP ID not set.');
}
if (empty($fb_app_secret)) {
throw new \LogicException('Facebook APP SECRET not set.');
}
FacebookSession::setDefaultApplication($fb_app_id, $fb_app_secret);
try {
$session = new FacebookSession($request->request($identifier));
} catch (FacebookRequestException $e) {
$response->setError(401, 'invalid_grant', $e->getMessage());
return null;
} catch (\Exception $e) {
$response->setError(401, 'invalid_grant', $e->getMessage());
return null;
}
if (!empty($session)) {
try {
$user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
$email = $user_profile->getProperty('email');
if (empty($email)) {
$response->setError(400, 'invalid_request', "User's email address not available.");
return null;
} else {
$userInfo = $this->storage->getUserInfoByFacebookId($user_profile->getId());
if (empty($userInfo)) {
$this->storage->createFacebookUser($user_profile);
$userInfo = $this->storage->getUserInfoByFacebookId($user_profile->getId());
}
}
} catch (FacebookRequestException $e) {
$response->setError(401, 'invalid_grant', $e->getMessage());
return null;
}
} else {
$response->setError(401, 'invalid_grant', 'Facebook session could not be set with supplied access token.');
return null;
}
if (empty($userInfo)) {
$response->setError(400, 'invalid_grant', 'Unable to retrieve user information.');
return null;
}
if (!isset($userInfo['user_id'])) {
throw new \LogicException("You must set the user_id on the array.");
}
$this->userInfo = $userInfo;
return true;
}
示例10: getUser
public function getUser($userId = 'me')
{
try {
$request = new FacebookRequest($this->getSession(), 'GET', '/' . $userId);
return $request->execute()->getGraphObject(GraphUser::className())->asArray();
} catch (Exception $e) {
}
return [];
}
示例11: testMeReturnsGraphUser
public function testMeReturnsGraphUser()
{
$response = (new FacebookRequest(FacebookTestHelper::$testSession, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
$info = FacebookTestHelper::$testSession->getSessionInfo();
$this->assertTrue($response instanceof GraphUser);
$this->assertEquals($info->getId(), $response->getId());
$this->assertNotNull($response->getName());
$this->assertNotNull($response->getLastName());
$this->assertNotNull($response->getLink());
}
示例12: get_user_information
public function get_user_information($access_token)
{
$session = $this->get_session_from_token($access_token);
if (!$session->validate()) {
return false;
}
//*** Call api
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
return $response->getGraphObject(GraphUser::className());
}
示例13: getGraph
public function getGraph()
{
$request = new FacebookRequest($this->session, 'GET', '/me');
$response = $request->execute();
return $response->getGraphObject(GraphUser::className());
//echo "<img src='$image'/>";
//echo "<br>";
//echo "Hello $name <br>";
//echo "Email: $email <br>";
//echo "Your Facebook ID: $id <br>";
}
示例14: getGraphUser
/**
* getUserInfo
*
* @throws FacebookException
* @return GraphUser
*/
public function getGraphUser()
{
$url = '/me?fields=id,email,first_name,last_name,birthday,permissions';
try {
/** @var GraphUser $userProfile */
$userProfile = (new FacebookRequest($this->session, 'GET', $url))->execute()->getGraphObject(GraphUser::className());
return $userProfile;
} catch (FacebookRequestException $e) {
throw new FacebookException($e->getMessage());
}
}
示例15: testAsList
public function testAsList()
{
$backingData = array('data' => array(array('id' => 1, 'name' => 'David'), array('id' => 2, 'name' => 'Fosco')));
$enc = json_encode($backingData);
$response = new FacebookResponse(null, json_decode($enc), $enc);
$list = $response->getGraphObjectList(GraphUser::className());
$this->assertEquals(2, count($list));
$this->assertTrue($list[0] instanceof GraphObject);
$this->assertTrue($list[1] instanceof GraphObject);
$this->assertEquals('David', $list[0]->getName());
$this->assertEquals('Fosco', $list[1]->getName());
}