当前位置: 首页>>代码示例>>PHP>>正文


PHP Facebook::getUser方法代码示例

本文整理汇总了PHP中Facebook::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::getUser方法的具体用法?PHP Facebook::getUser怎么用?PHP Facebook::getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Facebook的用法示例。


在下文中一共展示了Facebook::getUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: facebook

function facebook()
{
    global $template;
    $facebook = new Facebook(array('appId' => FB_APPID, 'secret' => FB_APPSECRET));
    $user = $facebook->getUser();
    if ($user) {
        try {
            $pages = $facebook->api('/me/accounts');
            $template->set('pages', $pages);
            $permissions = $facebook->api("/me/permissions");
            $publish_actions = 0;
            $manage_pages = 0;
            foreach ($permissions['data'] as $permission) {
                if ($permission['permission'] == 'publish_actions') {
                    $publish_actions = 1;
                }
                if ($permission['permission'] == 'manage_pages') {
                    $manage_pages = 1;
                }
            }
            if ($publish_actions == 0 || $manage_pages == 0) {
                throw new Exception("Oops");
            }
        } catch (Exception $e) {
            $url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
            header("Location: " . $url);
            exit;
        }
    } else {
        $url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
        header("Location: " . $url);
        exit;
    }
}
开发者ID:anantgarg,项目名称:kudos,代码行数:34,代码来源:connect.php

示例2: runAuth

 /**
  * Redirect user to facebook to obtain params
  * @return string - user id
  */
 public function runAuth()
 {
     $user = $this->facebook->getUser();
     if (!$user) {
         if (!$this->isAjax()) {
             redirect($this->getLoginUrl());
         } else {
             // output json
             $this->renderJson(array('loginUrl' => $this->getLoginUrl()));
         }
     }
     return $user;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:17,代码来源:Auth.php

示例3: login

 /**
  * Log a user in
  * @return Array Userdata
  * @throws FacebookApiException
  */
 public function login($grabUserImage = false)
 {
     $uid = $this->_client->getUser();
     $accessToken = $this->_client->getAccessToken();
     // If a user is authenticated, $userData will be filled with user data
     $userData = $this->_client->api('/me');
     if ($grabUserImage) {
         $apiUrl = '/' . $this->_client->getUser() . '/picture?redirect=0&type=large';
         $picture = $this->_client->api($apiUrl);
         $userData['imageUrl'] = $picture['data']['url'];
     }
     $userData['access_token'] = $accessToken;
     return $userData;
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:19,代码来源:Facebook.php

示例4: getInput

 public function getInput()
 {
     if ($this->fb->getUser()) {
         $user = $this->fb->getUser();
         $profile = $this->fb->api("/me?fields=id,name,picture");
         $label = "<img src='" . $profile['picture']['data']['url'] . "' />" . $profile['name'];
         $logout = $this->fb->getLogoutUrl(array('next' => JURI::base()));
         return $label . "<br /><a href='" . $logout . "'>Log out of Facebook</a>";
     } else {
         // Not logged in - display a login link
         $uri = JURI::current();
         $loginUrl = $this->fb->getLoginUrl(array('redirect_uri' => "http://aquinas.dphin.co.uk/login/profile?layout=edit"));
         return "<a href='" . $loginUrl . "'>Connect your Facebook account</a>";
     }
 }
开发者ID:SheffieldWalkingGroup,项目名称:swgwebsite,代码行数:15,代码来源:facebooklogin.php

示例5: call

 public function call()
 {
     //echo $this->_fbLoginRedirectUrl;exit;
     // Create our Application instance (replace this with your appId and secret).
     $facebook = new Facebook(array('appId' => $this->_fbAppId, 'secret' => $this->_fbAppSecret, 'cookie' => false));
     // Get User ID
     $this->_fbUser = $facebook->getUser();
     // We may or may not have this data based on whether the user is logged in.
     // If we have a $user id here, it means we know the user is logged into
     // Facebook, but we don't know if the access token is valid. An access
     // token is invalid if the user logged out of Facebook.
     if ($this->_fbUser) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $this->_fbUserProfile = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             error_log($e);
             $this->_fbUser = null;
         }
     }
     // Login or logout url will be needed depending on current user state.
     if ($this->_fbUser) {
         $this->_fbLogoutUrl = $facebook->getLogoutUrl(array("next" => $this->_fbLogoutRedirectUrl));
     } else {
         $this->_fbLoginUrl = $facebook->getLoginUrl(array('redirect_uri' => $this->_fbLoginRedirectUrl));
         //echo $this->_fbLoginUrl;exit;
     }
 }
开发者ID:vmangla,项目名称:evendor,代码行数:28,代码来源:FBConnect.php

示例6: face

 private function face($access_token, $dataConfig)
 {
     require_once 'php-sdk/src/facebook.php';
     $facebook = new Facebook($dataConfig);
     $facebook->setAccessToken($access_token);
     Zend_Debug::dump($user = $facebook->getUser());
     if ($user) {
         $this->view->faceUrl = $facebook->getLogoutUrl();
     } else {
         $this->view->faceUrl = $facebook->getLoginUrl();
     }
     Zend_Debug::dump($_REQUEST);
     Zend_Debug::dump($naitik = $facebook->api('/100000874886897'));
     if ($user) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $user_profile = $facebook->api('/me');
             print_r($user_profile);
         } catch (FacebookApiException $e) {
             error_log($e);
             $user = null;
         }
     }
     $this->view->user = $naitik;
 }
开发者ID:raphaeldealmeida,项目名称:Demagogos,代码行数:25,代码来源:IndexController.php

示例7: doLogin

 public function doLogin()
 {
     $code = Input::get('code');
     if (strlen($code) == 0) {
         return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');
     }
     $facebook = new Facebook(Config::get('facebook'));
     $uid = $facebook->getUser();
     if ($uid == 0) {
         return Redirect::to('/')->with('message', 'There was an error');
     }
     $me = $facebook->api('/me', ['fields' => ['id', 'first_name', 'last_name', 'picture', 'email', 'gender']]);
     $profile = Profile::whereUid($uid)->first();
     if (empty($profile)) {
         $user = new User();
         $user->name = $me['first_name'] . ' ' . $me['last_name'];
         $user->email = $me['email'];
         $user->photo = 'https://graph.facebook.com/' . $me['id'] . '/picture?type=large';
         $user->save();
         $profile = new Profile();
         $profile->uid = $uid;
         $profile->username = $me['id'];
         $profile->gender = $me['gender'];
         $profile = $user->profiles()->save($profile);
     }
     $profile->access_token = $facebook->getAccessToken();
     $profile->save();
     $user = $profile->user;
     Auth::login($user);
     return Redirect::to('/')->with('message', 'Logged in with Facebook');
 }
开发者ID:talha08,项目名称:Login-With-Facebook,代码行数:31,代码来源:FacebookController.php

示例8: connectFacebook

 function connectFacebook()
 {
     $this->autoRender = false;
     $facebook = new Facebook(array('appId' => $this->facebookAppId, 'secret' => $this->facebookSecret));
     $user = $facebook->getUser();
     if ($user) {
         try {
             $user_profile = $facebook->api('/me');
             $userinfo = $this->User->find('first', array('conditions' => array('User.username' => isset($user_profile['id']) ? $user_profile['id'] : $user_profile['email'], 'User.social_connect' => 'facebook')));
             if (empty($userinfo)) {
                 $data['User']['username'] = isset($user_profile['id']) ? $user_profile['id'] : $user_profile['email'];
                 $data['User']['password'] = $user_profile['id'];
                 $data['User']['group_id'] = $this->socialLoginGroupId;
                 $data['User']['social_connect'] = 'facebook';
                 $data['User']['social_info'] = json_encode($user_profile);
                 $this->User->create();
                 $this->User->save($data);
                 $userinfo = $this->User->find('first', array('conditions' => array('User.id' => $this->User->id)));
                 $this->makeUserLogin($userinfo);
             } else {
                 $this->makeUserLogin($userinfo);
             }
         } catch (Exception $e) {
             error_log($e->getMessage());
             $this->Session->setFlash($e->getMessage());
             $user = NULL;
         }
     } else {
         $this->Session->setFlash('Sorry.Please try again');
     }
     $this->render('Social/close_window');
 }
开发者ID:ngdinhbinh,项目名称:libu,代码行数:32,代码来源:SocialController.php

示例9: acceptLogin

 public function acceptLogin()
 {
     $facebook = new Facebook(array('appId' => '1494342414191651', 'secret' => '775288a56787896f92da0f2096c6de7c'));
     if (!is_null($this->session->userdata('fb'))) {
         //redirect('/');
         redirect('/home');
     } else {
         $user = $facebook->getUser();
         if ($user) {
             $user_profile = null;
             try {
                 //Proceed knowing you have a logged in user who's authenticated.
                 $user_profile = $facebook->api('/me');
                 var_dump($user_profile);
             } catch (FacebookApiException $e) {
                 error_log($e);
                 //$user = null;
                 $this->loadview('404');
             }
             $logoutUrl = $facebook->getLogoutUrl();
             $data = array('fb' => array('user_id' => $user, 'name' => $user_profile['name'], 'logout' => $logoutUrl));
             $this->session->set_userdata($data);
             redirect('/');
         } else {
             header('Location:' . $facebook->getLoginUrl());
             //$this->load->view('404');
             //$this->loadview('404');
         }
     }
 }
开发者ID:binhhv,项目名称:job,代码行数:30,代码来源:Welcome.php

示例10: fbpromo_clientarea

function fbpromo_clientarea($vars)
{
    global $_LANG;
    require dirname(__FILE__) . "/src/facebook.php";
    $app_id = fbpromo_get_addon('appid');
    $application_secret = fbpromo_get_addon('appsecret');
    $facebook = new Facebook(array('appId' => $app_id, 'secret' => $application_secret));
    // Get User ID
    $user = $facebook->getUser();
    // We may or may not have this data based on whether the user is logged in.
    //
    // If we have a $user id here, it means we know the user is logged into
    // Facebook, but we don't know if the access token is valid. An access
    // 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;
        }
    }
    require dirname(__FILE__) . '/clientarea.php';
    die;
}
开发者ID:carriercomm,项目名称:fbpromo,代码行数:26,代码来源:fbpromo.php

示例11: getFacebookUserDetails

function getFacebookUserDetails($params)
{
    //$graph_url = "https://graph.facebook.com/me?access_token=$access_token";
    //
    // 	$ch = curl_init();
    // 	curl_setopt($ch, CURLOPT_URL, $graph_url);
    // 	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // 	$user = @json_decode(curl_exec($ch));
    //	curl_close($ch);
    //    return $user;
    //die(print_r(realpath(dirname(__FILE__))));
    //echo '8888';
    //$CI =& get_instance();
    //echo '7777';
    //$CI->load->library('facebook');
    //die( base_url() );
    //echo 'base...'.$params->base_dir;
    require_once $params->base_dir . '/server/facebook.php';
    $facebook = new Facebook(array('appId' => $params->app_id, 'secret' => $params->app_secret));
    $user = $facebook->getUser();
    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;
        }
        return $user_profile;
    }
}
开发者ID:vlad1500,项目名称:example-code,代码行数:32,代码来源:fb_helper.php

示例12: Facebook

 function try_connect($pubit = 0, $stUrl = '', $PublishMessage = '')
 {
     $myparams =& JComponentHelper::getParams('com_fbjconnect');
     $getappid = $myparams->get('appid');
     $getappsec = $myparams->get('appsecret');
     $access_token = "";
     $uid = "";
     $postresult = false;
     $facebook = new Facebook(array('appId' => $getappid, 'secret' => $getappsec, 'cookie' => true));
     $session = $facebook->getSession();
     $me = null;
     $uid = "";
     if ($session) {
         try {
             $access_token = $facebook->getAccessToken();
             $me = $facebook->api('/me');
             $uid = $facebook->getUser();
             if ($pubit == 1) {
                 $fbpic = JURI::base() . 'modules/mod_jfbgconnect/fgimage.jpg';
                 $postresult = $facebook->api('/me/feed/', 'post', array('access_token' => $access_token, 'picture' => $fbpic, 'link' => $stUrl, 'message' => $PublishMessage));
             }
         } catch (FacebookApiException $e) {
             error_log($e);
         }
     }
     return array($uid, $me, $session, $access_token, $postresult);
 }
开发者ID:akksi,项目名称:jcg,代码行数:27,代码来源:fbgccontroller.php

示例13: login

 /**
  * Function for check login
  *
  */
 public function login()
 {
     // Setting the page title
     $this->set("title_for_layout", "User Login");
     if ($this->Auth->login()) {
         $this->redirect($this->Auth->redirect());
     } else {
         if ($this->request->is('post')) {
             $this->Session->setFlash(__('Invalid username or password, try again'));
         }
     }
     $facebooksecretkey = '4753a9042404a78aaff1069f73aa8994';
     $facebookapikey = '203755806382341';
     App::import('Vendor', 'facebook', array('file' => 'facebook/src/facebook.php'));
     $facebook = new Facebook(array('appId' => "{$facebookapikey}", 'secret' => "{$facebooksecretkey}"));
     $user = $facebook->getUser();
     $facebookLoginUrl = $facebook->getLoginUrl();
     $this->set('facebookLoginUrl', $facebookLoginUrl);
     if ($user) {
         $faceBookUserProfile = $facebook->api('/me');
         if (isset($faceBookUserProfile) && !empty($faceBookUserProfile)) {
             $this->facebook($faceBookUserProfile);
         }
     }
     //ends here
 }
开发者ID:piotr0beschel,项目名称:manage-products,代码行数:30,代码来源:UsersController.php

示例14: get_user_data_fb

 public function get_user_data_fb()
 {
     parse_str($_SERVER['QUERY_STRING'], $_REQUEST);
     $facebook = new Facebook(array('appId' => '876274572459160', 'secret' => 'c44768470ff9f9d7a52784f6f5fbfd9a', 'cookie' => true, 'redirect_uri' => 'kepoabis.com'));
     Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
     Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
     $user = $facebook->getUser();
     $user_data = array();
     if ($user) {
         try {
             $user_data = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             error_log($e);
             $user = null;
         }
     }
     $url = "";
     $img = "";
     if ($user) {
         $url = "<strong><em>You are connected with Facebook.<br></em></strong>";
         //$facebook->getLogoutUrl();
         $img = "https://graph.facebook.com/" . $user . "/picture";
     } else {
         $url = "<a class='btn btn-default btn-social btn-facebook' href=" . $facebook->getLoginUrl() . "><i class='fa fa-facebook'></i>Sign in with Facebook</a>";
     }
     return array("url" => $url, "img" => $img, "is_login" => $user, "user_data" => $user_data);
 }
开发者ID:kepoabiscom,项目名称:kepe-dev,代码行数:27,代码来源:comment.php

示例15: loginWithFacebook

 /**
  * Try to login with Facebook and return true on success
  * @return boolean
  */
 protected function loginWithFacebook()
 {
     $objFacebook = new Facebook(array('appId' => $this->fblogin_appId, 'secret' => $this->fblogin_appKey));
     $arrProfile = false;
     if ($objFacebook->getUser() > 0) {
         try {
             $arrProfile = $objFacebook->api('/me?fields=id,name,first_name,last_name,email,gender');
         } catch (FacebookApiException $e) {
             $arrProfile = false;
             $this->log('Could not fetch the Facebook data: ' . $e->getMessage(), 'ModuleFacebookLogin loginWithFacebook()', TL_ERROR);
         }
     }
     // Log the error message
     if (!$arrProfile) {
         $this->log('Could not fetch the Facebook user.', 'ModuleFacebookLogin loginWithFacebook()', TL_ERROR);
         return false;
     }
     $time = time();
     $objUser = $this->Database->prepare("SELECT id FROM tl_member WHERE fblogin=? AND login=1 AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND disable=''")->limit(1)->execute($arrProfile['id']);
     // Create a new user if none found
     if (!$objUser->numRows) {
         $objUser = $this->createNewUser($arrProfile);
         if ($objUser === false) {
             return false;
         }
     }
     $this->import('FrontendUser', 'User');
     return $this->User->login($arrProfile);
 }
开发者ID:codefog,项目名称:contao-facebook_login,代码行数:33,代码来源:ModuleFacebookLogin.php


注:本文中的Facebook::getUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。