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


PHP Facebook类代码示例

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


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

示例1: requestToken

 public function requestToken($Account)
 {
     $NGPushIni = eZINI::instance('ngpush.ini');
     $SiteIni = eZINI::instance('site.ini');
     $AccessToken = $NGPushIni->variable($Account, 'AccessToken');
     // If access tokens are given
     if ($AccessToken) {
         //Save request signing tokens to cache
         ngPushBase::save_token($Account, $AccessToken, 'main_token');
     } else {
         $AdministrationUrl = '/';
         eZURI::transformURI($AdministrationUrl, false, 'full');
         $AdministrationUrl = base64_encode($AdministrationUrl);
         $SettingsBlock = base64_encode($Account);
         $redirectUrl = 'http://' . $NGPushIni->variable('PushNodeSettings', 'ConnectURL') . '/redirect.php/' . $AdministrationUrl . '/' . $SettingsBlock . '?case=facebook';
         $Facebook = new Facebook(array('appId' => $NGPushIni->variable($Account, 'AppAPIKey'), 'secret' => $NGPushIni->variable($Account, 'AppSecret')));
         $Permissions = array('publish_actions', 'user_posts');
         if ($NGPushIni->variable($Account, 'EntityType') == 'page') {
             $Permissions[] = 'manage_pages';
         }
         $state = md5(uniqid(rand(), true));
         $http = eZHTTPTool::instance();
         $http->setSessionVariable('ngpush_state', $state);
         $LoginUrl = $Facebook->getLoginUrl(array('redirect_uri' => $redirectUrl, 'scope' => implode($Permissions, ','), 'state' => $state));
         self::$response['RequestPermissionsUrl'] = $LoginUrl;
     }
 }
开发者ID:netgen,项目名称:ngpush,代码行数:27,代码来源:ngpush_facebook_base.php

示例2: authenticateFacebook

	public function authenticateFacebook() {
		$fbconfig = Yum::module()->facebookConfig;
		if (!$fbconfig || $fbconfig && !is_array($fbconfig))
			throw new Exception('actionLogout for Facebook was called, but is not activated in application configuration');

		Yii::import('application.modules.user.vendors.facebook.*');
		require_once('Facebook.php');
		$facebook = new Facebook($fbconfig);

		$fb_uid = $facebook->getUser();
		$profile = YumProfile::model()->findByAttributes(array('facebook_id'=>$fb_uid));
		$user = ($profile) ? YumUser::model()->findByPk($profile->user_id) : null;
		if ($user === null)
			$this->errorCode = self::ERROR_USERNAME_INVALID;
		else if($user->status == YumUser::STATUS_INACTIVE)
			$this->errorCode = self::ERROR_STATUS_INACTIVE;
		else if($user->status == YumUser::STATUS_BANNED)
			$this->errorCode = self::ERROR_STATUS_BANNED;
		else
		{
			$this->id = $user->id;
			$this->username = 'facebook';
			$this->facebook_id = $fb_uid;
			//$this->facebook_user = $facebook->api('/me');
			$this->errorCode = self::ERROR_NONE;
		}
	}
开发者ID:richardh68,项目名称:yii-user-management,代码行数:27,代码来源:YumUserIdentity.php

示例3: 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

示例4: test_fb_connection

 protected function test_fb_connection($debug = false)
 {
     if ($this->configured) {
         $stime = microtime(true);
         // is configured, so lets make sure the App ID and Secret are valid
         include_once 'libs/facebook.php';
         $fb = new Facebook(array('appId' => $this->app_id, 'secret' => $this->app_secret));
         $error = false;
         try {
             $resp = $fb->api(array('method' => 'admin.getAppProperties', 'properties' => 'connect_url'));
         } catch (Exception $e) {
             $error = true;
             echo $debug ? '<p class="error">There is an error with your Facebook settings: "' : '';
             echo $debug ? "Error #{$e->getCode()}: {$e->getMessage()}\"." : '';
             switch ($e->getCode()) {
                 case 104:
                     echo $debug ? ' This probably means your <strong>Application ID</strong> is incorrect.' : '';
                     break;
                 case 190:
                     echo $debug ? ' This probably means your <strong>Application Secret</strong> is incorrect.' : '';
                     break;
             }
             echo $debug ? '</p>' : '';
         }
         $etime = microtime(true);
         $time = $etime - $stime;
         #			echo "Facebook check took $time seconds\n";
         $this->connected = !$error;
         return !$error;
     } else {
         return false;
         # not configured, so let's not even try to connect!
     }
 }
开发者ID:google-code-backups,项目名称:pumpmyvote,代码行数:34,代码来源:fbregister.php

示例5: fb

 function fb()
 {
     $this->load->config('facebook');
     include_once APPPATH . 'third_party/facebook.php';
     $facebook = new Facebook(array('appId' => $this->config->item('facebook_app_id'), 'secret' => $this->config->item('facebook_api_secret'), 'cookie' => true));
     $session = $facebook->getSession();
     if (isset($session['uid'])) {
         $me = $facebook->api('/me');
         // kalo login fb apakah ada user ini
         $rows = $this->db->get_where('meta', array('fb_id' => $session['uid']))->row();
         if ($rows) {
             $row = $this->ion_auth->get_user_by_email($me['email']);
             $this->ion_auth_model->update_last_login($row->id);
             $session_data = array('email' => $row->email, 'id' => $row->id, 'user_id' => $row->id, 'group_id' => $row->group_id, 'group' => $row->group);
             $this->session->set_userdata($session_data);
             redirect($this->url_if_login);
         } else {
             $this->session->set_flashdata('message', 'Can\'t Find Your FB accounts mapping to our database member');
             redirect('member/registration/');
         }
     } else {
         $this->session->set_flashdata('message', 'Please Login To Your Facebook First');
         redirect('member/login', 'refresh');
     }
 }
开发者ID:ramatraya,项目名称:Cecille,代码行数:25,代码来源:login.php

示例6: loadUserByUsername

 public function loadUserByUsername($username)
 {
     $user = $this->findUserByFbId($username);
     try {
         $fbdata = $this->facebook->api('/me');
     } catch (FacebookApiException $e) {
         $fbdata = null;
     }
     if (!empty($fbdata)) {
         if (empty($user)) {
             if (!isset($fbdata['email']) || $fbdata['email'] == '') {
                 // TODO: the user was found obviously, but doesnt match our expectations, do something smart
                 throw new UsernameNotFoundException('Une erreur est survenue lors de votre connexion...');
             }
             $user = $this->userManager->createUser();
             $user->setEnabled(true);
             $user->setPassword('');
         }
         if ($user->getUsername() == '' || $user->getUsername() == null) {
             $user->setUsername($username . '@facebook.com');
         }
         $user->setFBData($fbdata);
         if (count($this->validator->validate($user, 'Facebook'))) {
             // TODO: the user was found obviously, but doesnt match our expectations, do something smart
             throw new UsernameNotFoundException('Une erreur est survenue lors de votre connexion...');
         }
         $this->userManager->updateUser($user);
     }
     if (empty($user)) {
         // TODO: the user was found obviously, but doesnt match our expectations, do something smart
         throw new UsernameNotFoundException('Une erreur est survenue lors de votre connexion...');
     }
     return $user;
 }
开发者ID:gitter-badger,项目名称:Doctors,代码行数:34,代码来源:FacebookProvider.php

示例7: post_facebook_link_to_post

function post_facebook_link_to_post(array $post)
{
    $post_text = construct_post_text($post);
    $facebook = new Facebook(array('appId' => FacebookCredentials::$app_id, 'secret' => FacebookCredentials::$app_secret, 'cookie' => true));
    $req = array('access_token' => FacebookCredentials::$access_token, 'message' => $post_text);
    $res = $facebook->api('/me/feed', 'POST', $req);
}
开发者ID:avioli,项目名称:secondcrack,代码行数:7,代码来源:post_fb.php

示例8: requireAuthenticate

 static function requireAuthenticate($is_ajax = true, $extra_secure = true, &$realUser = null)
 {
     global $api_key, $api_key_secret, $adminUserIDs;
     $u = MyAuth::checkAuthentication($extra_secure);
     if (!$u) {
         if ($is_ajax) {
             return 0;
         }
         $facebook = new Facebook($api_key, $api_key_secret);
         $user = $facebook->require_login();
         if ($user) {
             MyAuth::setLoginAuthenticate($user);
         }
         $u = $user;
     }
     if (isset($realUser)) {
         $realUser = $u;
     }
     //Return the mock_user if the real user is an administrator and mockuser is set
     $mu = GetAdminDebug('mock_user');
     if ($mu != 'NONE' && in_array(intval($u), $adminUserIDs)) {
         return $mu;
     } else {
         return $u;
     }
 }
开发者ID:soychicka,项目名称:tg,代码行数:26,代码来源:FbAuth.php

示例9: 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

示例10: fb

 function fb()
 {
     $this->load->config('facebook');
     include_once APPPATH . 'third_party/facebook.php';
     $facebook = new Facebook(array('appId' => $this->config->item('facebook_app_id'), 'secret' => $this->config->item('facebook_api_secret'), 'cookie' => true));
     $signed = $facebook->getSignedRequest();
     if (isset($signed['registration'])) {
         $username = $signed['registration']['name'];
         $password = $signed['registration']['password'];
         $email = $signed['registration']['email'];
         $additional_data = array('fullname' => $username, 'fb_id' => $signed['user_id'], 'fb_oauth_token' => $signed['oauth_token'], 'avatar' => 'http://graph.facebook.com/' . $signed['user_id'] . '/picture');
         $registration = $this->ion_auth->register($username, $password, $email, $additional_data);
         if ($registration) {
             //langsung auto login lah
             if ($this->ion_auth->login($email, $password)) {
                 redirect('/member/');
                 return;
             } else {
                 echo 'successfully registered but no login';
                 return;
             }
         } else {
             $this->tpl['error'] = $this->ion_auth->errors();
         }
     }
     $this->tpl['content'] = $this->load->view('registration_fb', $this->tpl, true);
     $this->load->view('member/body', $this->tpl);
 }
开发者ID:ramatraya,项目名称:Cecille,代码行数:28,代码来源:registration.php

示例11: 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

示例12: facebook_init

function facebook_init()
{
    require 'src/facebook.php';
    global $facebook;
    $facebook = new Facebook(array('appId' => FB_KEY, 'secret' => FB_SECRET));
    if (!empty($_SESSION) && !empty($_SESSION['fb_code'])) {
        $url = "https://graph.facebook.com/oauth/access_token?";
        $params = array();
        $params[] = 'client_id=' . $facebook->getAppId();
        $params[] = 'redirect_uri=' . 'http://' . HOST . get_url('/facebook/auth/');
        $params[] = 'client_secret=' . $facebook->getApiSecret();
        $params[] = 'code=' . $_SESSION['fb_code'];
        $url .= implode('&', $params);
        $data = explode('&', get_data($url));
        foreach ($data as &$d) {
            $d = explode('=', $d);
            if ($d[0] == 'access_token') {
                $_SESSION['fb_access_token'] = $d[1];
            } elseif ($d[0] == 'expires') {
                $_SESSION['fb_at_expires'] = time() + $d[1];
            }
        }
    }
    if (array_key_exists('fb_access_token', $_SESSION)) {
        if ($_SESSION['fb_at_expires'] > time()) {
            $facebook->setAccessToken($_SESSION['fb_access_token']);
            unset($_SESSION['fb_code']);
        }
    }
}
开发者ID:nodefortytwo,项目名称:engagement,代码行数:30,代码来源:facebook.php

示例13: 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

示例14: 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

示例15: process_request

 public function process_request($request)
 {
     if ($request == 'facebook-login') {
         $app_id = qa_opt('facebook_app_id');
         $app_secret = qa_opt('facebook_app_secret');
         $tourl = qa_get('to');
         if (!strlen($tourl)) {
             $tourl = qa_path_absolute('');
         }
         if (strlen($app_id) && strlen($app_secret)) {
             require_once $this->directory . 'facebook.php';
             $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
             $fb_userid = $facebook->getUser();
             if ($fb_userid) {
                 try {
                     $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)');
                     if (is_array($user)) {
                         qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null));
                     }
                 } catch (FacebookApiException $e) {
                 }
             } else {
                 qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
             }
         }
         qa_redirect_raw($tourl);
     }
 }
开发者ID:amiyasahu,项目名称:question2answer,代码行数:28,代码来源:qa-facebook-login-page.php


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