Esempio n. 1
0
 /**
  * Runs an FQL query and return its content
  *
  * @param String $query A valid FQL query
  * @param String $castAs Cast the result as a specialized GraphObject (GraphAlbum, GraphLocation, GraphUser)
  * @return GraphObject
  */
 public function executeFQLQuery($query, $castAs = NULL)
 {
     if ($castAs === NULL) {
         $castAs = GraphObject::className();
     }
     return (new FacebookRequest($this->facebookSession, 'GET', '/fql', ['access_token' => $this->facebookSession->getToken(), 'q' => $query]))->execute()->getGraphObject($castAs);
 }
Esempio n. 2
0
 public function facebook()
 {
     $facebook_default_scope = explode(',', $this->ci->config->item("facebook_default_scope"));
     $facebook_app_id = $this->ci->config->item("facebook_app_id");
     $facebook_api_secret = $this->ci->config->item("facebook_api_secret");
     // init app with app id and secret
     FacebookSession::setDefaultApplication($facebook_app_id, $facebook_api_secret);
     // login helper with redirect_uri
     $helper = new FacebookRedirectLoginHelper(site_url('login/facebook'));
     // see if a existing session exists
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         // create new session from saved access_token
         $session = new FacebookSession($_SESSION['fb_token']);
         // validate the access_token to make sure it's still valid
         try {
             if (!$session->validate()) {
                 $session = null;
             }
         } catch (Exception $e) {
             // catch any exceptions
             $session = null;
         }
     }
     if (!isset($session) || $session === null) {
         // no session exists
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
             // handle this better in production code
             print_r($ex);
         } catch (Exception $ex) {
             // When validation fails or other local issues
             // handle this better in production code
             print_r($ex);
         }
     }
     // see if we have a session
     if (isset($session)) {
         // save the session
         $_SESSION['fb_token'] = $session->getToken();
         // create a session using saved token or the new one we generated at login
         $session = new FacebookSession($session->getToken());
         // graph api request for user data
         //$request = new FacebookRequest($session, 'GET', '/me/friends');
         $request = new FacebookRequest($session, 'GET', '/me?fields=id,name,picture,friends');
         $response = $request->execute();
         // get response
         $graphObject = $response->getGraphObject()->asArray();
         $fb_data = array('me' => $graphObject, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
         $this->ci->session->set_userdata('fb_data', $fb_data);
     } else {
         $fb_data = array('me' => null, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
         $this->ci->session->set_userdata('fb_data', $fb_data);
     }
     return $fb_data;
 }
Esempio n. 3
0
 /**
  * @param string $accessToken
  * @param string $appId
  * @param string $appSecret
  * @throws \Vegas\Social\Exception
  */
 protected function connect($accessToken, $appId, $appSecret)
 {
     $session = new FacebookSession($accessToken);
     $session->setDefaultApplication($appId, $appSecret);
     if ($session->getToken() == $accessToken) {
         $this->fbSession = $session;
         $this->fbScope = $session->getSessionInfo()->getScopes();
         $this->checkPermissions();
         return $this;
     }
     $this->fbSession = false;
     throw new \Vegas\Social\Exception\InvalidSessionException();
 }
 private function allpost()
 {
     $session = $this->getSession();
     $helper = $this->getHelper();
     if (isset($session)) {
         $_SESSION['fb_token'] = $session->getToken();
         $session = new FacebookSession($session->getToken());
         $request = new FacebookRequest($session, 'GET', '/me/feed');
         $response = $request->execute();
         //var_dump($response->getPageId());
         $graphObject = $response->getGraphObject()->asArray();
     }
     $data = json_decode(json_encode($graphObject), true);
     return $data;
 }
Esempio n. 5
0
 public function __construct($app_id, $app_secret, $redirectURI)
 {
     FacebookSession::setDefaultApplication($app_id, $app_secret);
     $this->loginHelper = new FacebookRedirectLoginHelper($redirectURI);
     // see if a existing session exists
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         $session = new FacebookSession($_SESSION['fb_token']);
         // create new session from saved access_token
         // validate the access_token to make sure it's still valid
         try {
             if (!$session->validate()) {
                 $session = null;
             }
         } catch (Exception $e) {
             $session = null;
         }
     } else {
         // no session exists
         try {
             $session = $this->loginHelper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             $session = null;
             var_dump($ex);
         } catch (Exception $ex) {
             $session = null;
             var_dump($ex);
         }
     }
     // see if we have a session
     if (isset($session)) {
         $_SESSION['fb_token'] = $session->getToken();
         // Save the token
         $session = new FacebookSession($session->getToken());
         // create a session using saved token or the new one we generated at login
     } else {
         $session = null;
     }
     $this->session = $session;
 }
Esempio n. 6
0
        // print_r($session);
    } catch (FacebookRequestException $ex) {
        print_r($ex);
    } catch (Exception $ex) {
        print_r($ex);
    }
}
$google_session_token = "";
// see if we have a session
if (isset($session)) {
    //echo "session cretaed _ ". $session;
    //require_once( 'libs/resize_image.php' );
    $_SESSION['fb_login_session'] = $session;
    $_SESSION['fb_token'] = $session->getToken();
    // create a session using saved token or the new one we generated at login
    $session = new FacebookSession($session->getToken());
    //print_r($session );
    $request_user_details = new FacebookRequest($session, 'GET', '/me?fields=id,name');
    $response_user_details = $request_user_details->execute();
    $user_details = $response_user_details->getGraphObject()->asArray();
    //print_r($session );
    $user_id = $user_details['id'];
    //$user_id = 1456168281369216;
    $user_name = $user_details['name'];
    if (isset($_SESSION['google_session_token'])) {
        $google_session_token = $_SESSION['google_session_token'];
    }
    ?>

				<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
					<div class="container">
Esempio n. 7
0
 /**
  * FacebookRequest - Returns a new request using the given session.  optional
  *   parameters hash will be sent with the request.  This object is
  *   immutable.
  *
  * @param FacebookSession $session
  * @param string $method
  * @param string $path
  * @param array|null $parameters
  * @param string|null $version
  * @param string|null $etag
  */
 public function __construct(FacebookSession $session, $method, $path, $parameters = null, $version = null, $etag = null)
 {
     $this->session = $session;
     $this->method = $method;
     $this->path = $path;
     if ($version) {
         $this->version = $version;
     } else {
         $this->version = static::GRAPH_API_VERSION;
     }
     $this->etag = $etag;
     $params = $parameters ?: array();
     if ($session && !isset($params['access_token'])) {
         $params['access_token'] = $session->getToken();
     }
     if (!isset($params['appsecret_proof']) && FacebookSession::useAppSecretProof()) {
         $params['appsecret_proof'] = $this->getAppSecretProof($params['access_token']);
     }
     $this->params = $params;
 }
Esempio n. 8
0
$app_secret = '';
$redirect_url = 'http://packetcode.com/apps/fbloginlogout/';
//3.Initialize application, create helper object and get fb sess
FacebookSession::setDefaultApplication($app_id, $app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
$sess = $helper->getSessionFromRedirect();
//check if facebook session exists
if (isset($_SESSION['fb_token'])) {
    $sess = new FacebookSession($_SESSION['fb_token']);
}
//logout
$logout = 'http://packetcode.com/apps/newfblogin&logout=true';
//4. if fb sess exists echo name
if (isset($sess)) {
    //store the token in the php session
    $_SESSION['fb_token'] = $sess->getToken();
    //create request object,execute and capture response
    $request = new FacebookRequest($sess, 'GET', '/me');
    // from response get graph object
    $response = $request->execute();
    $graph = $response->getGraphObject(GraphUser::classname());
    // use graph object methods to get user details
    $name = $graph->getName();
    $id = $graph->getId();
    $image = 'https://graph.facebook.com/' . $id . '/picture?width=300';
    $email = $graph->getProperty('email');
    echo "hi {$name} <br>";
    echo "your email is {$email} <br><Br>";
    echo "<img src='{$image}' /><br><br>";
    echo "<a href='" . $logout . "'><button>Logout</button></a>";
} else {
 public function testSessionToken()
 {
     $session = new FacebookSession(FacebookTestHelper::getAppToken());
     $this->assertEquals(FacebookTestHelper::getAppToken(), $session->getToken());
 }
Esempio n. 10
0
 public function testSessionToken()
 {
     $session = new FacebookSession(FacebookTestCredentials::$appToken);
     $this->assertEquals(FacebookTestCredentials::$appToken, $session->getToken());
 }
 /**
  * Returns the URL to send the user in order to log out of Facebook.
  *
  * @param FacebookSession $session The session that will be logged out
  * @param string $next The url Facebook should redirect the user to after
  *   a successful logout
  *
  * @return string
  */
 public function getLogoutUrl(FacebookSession $session, $next)
 {
     $params = array('next' => $next, 'access_token' => $session->getToken());
     return 'https://www.facebook.com/logout.php?' . http_build_query($params, null, '&amp;');
 }
Esempio n. 12
0
    } catch (FacebookRequestException $ex) {
        // When Facebook returns an error
        // handle this better in production code
        print_r($ex);
    } catch (Exception $ex) {
        // When validation fails or other local issues
        // handle this better in production code
        print_r($ex);
    }
}
// see if we have a session
if (isset($session)) {
    // save the session
    $_SESSION['fb_token'] = $session->getToken();
    // create a session using saved token or the new one we generated at login
    $session = new FacebookSession($session->getToken());
    // graph api request for user data
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    // get response
    $graphObject = $response->getGraphObject()->asArray();
    // print profile data
    echo '<pre>' . print_r($graphObject, 1) . '</pre>';
    echo '<pre>' . $session->getToken() . '</pre>';
    $user = $response->getGraphObject(GraphUser::className());
    $userId = $user->getId();
    echo $userId;
    // graph api request for user friends
    $request1 = new FacebookRequest($session, 'GET', '/me/friends');
    $response1 = $request1->execute();
    // get response
Esempio n. 13
0
 public function simplefbpost()
 {
     // init app with app id and secret
     FacebookSession::setDefaultApplication($this->facebook_app_id, $this->facebook_api_secret);
     // login helper with redirect_uri
     $helper = new FacebookRedirectLoginHelper(site_url('landing/index'));
     // see if a existing session exists
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         // create new session from saved access_token
         $session = new FacebookSession($_SESSION['fb_token']);
         // validate the access_token to make sure it's still valid
         try {
             if (!$session->validate()) {
                 $session = null;
             }
         } catch (Exception $e) {
             // catch any exceptions
             $session = null;
         }
     }
     if (!isset($session) || $session === null) {
         // no session exists
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
             // handle this better in production code
             print_r($ex);
         } catch (Exception $ex) {
             // When validation fails or other local issues
             // handle this better in production code
             print_r($ex);
         }
     }
     if (isset($session)) {
         // save the session
         $_SESSION['fb_token'] = $session->getToken();
         // create a session using saved token or the new one we generated at login
         $session = new FacebookSession($session->getToken());
         try {
             // with this session I will post a message to my own timeline
             $request = new FacebookRequest($session, 'POST', '/me/feed', array('link' => 'www.purnimapro.com', 'message' => 'Complete IT Solutions'));
             $response = $request->execute();
             $graphObject = $response->getGraphObject();
             // the POST response object
             echo '<pre>' . print_r($graphObject, 1) . '</pre>';
             $msgid = $graphObject->getProperty('id');
         } catch (FacebookRequestException $e) {
             // show any error for this facebook request
             echo 'Facebook (post) request error: ' . $e->getMessage();
         }
         if (isset($msgid)) {
             // we only need to the sec. part of this ID
             $parts = explode('_', $msgid);
             try {
                 $request2 = new FacebookRequest($session, 'GET', '/' . $parts[1]);
                 $response2 = $request2->execute();
                 $graphObject2 = $response2->getGraphObject();
                 // the GET response object
                 echo '<pre>' . print_r($graphObject2, 1) . '</pre>';
             } catch (FacebookRequestException $e) {
                 // show any error for this facebook request
                 echo 'Facebook (get) request error: ' . $e->getMessage();
             }
         }
     } else {
         // we need to create a new session, provide a login link
         echo 'No session, please <a href="' . $helper->getLoginUrl(array('publish_actions')) . '">login</a>.';
     }
 }
Esempio n. 14
0
if (isset($_GET['type']) && $_GET['type'] == 'facebook') {
    $fb_url = $helper->getLoginUrl(array('email'));
    header('Location: ' . $fb_url);
}
$session = $helper->getSessionFromRedirect();
if (isset($_SESSION['token'])) {
    $session = new FacebookSession($_SESSION['token']);
    try {
        $session->validate(FB_APP_ID, FB_APP_SECRET);
    } catch (FacebookAuthorizationException $e) {
        echo $e->getMessage();
    }
}
$data = array();
if (isset($session)) {
    $_SESSION['token'] = $session->getToken();
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graph = $response->getGraphObject(GraphUser::className());
    $data = $graph->asArray();
    $id = $graph->getId();
    $image = "https://graph.facebook.com/" . $id . "/picture?width=100";
    $data['image'] = $image;
    if ($user_obj->fb_login($data)) {
        header('Location: home.php');
    } else {
        header('Location: index.php');
    }
}
/*********Facebook Login **********/
/*******Google ******/
Esempio n. 15
0
 public function setSession(FacebookSession $session)
 {
     $this->setAccessToken($session->getToken());
     $this->session = $session;
 }