function facebook_login(&$vars) { extract($vars); $app_id = environment('facebookAppId'); $consumer_key = environment('facebookKey'); $consumer_secret = environment('facebookSecret'); $agent = environment('facebookAppName') . " (curl)"; add_include_path(library_path()); add_include_path(library_path() . 'facebook-platform/php'); add_include_path(library_path() . 'facebook_stream'); require_once "facebook.php"; require_once "FacebookStream.php"; require_once "Services/Facebook.php"; $fb = new Facebook($consumer_key, $consumer_secret, true); $_SESSION['fb_session'] = (string) $fb->api_client->session_key; $_SESSION['fb_userid'] = (string) $fb->user; $fs = new FacebookStream($consumer_key, $consumer_secret, $agent); $fieldlist = array('last_name', 'first_name', 'pic_small', 'profile_blurb', 'profile_url', 'locale', 'name', 'proxied_email'); $fields = implode(',', $fieldlist); $user = $fs->GetInfo($app_id, $_SESSION['fb_session'], $_SESSION['fb_userid'], $fields); $values = array(); $values[] = str_replace(' ', '', strtolower((string) $user->user->name)); $values[] = (string) $user->user->pic_small; $values[] = (string) $user->user->name; $values[] = (string) $user->user->profile_blurb; $values[] = (string) $user->user->profile_url; $values[] = (string) $user->user->locale; $Identity =& $db->model('Identity'); $Person =& $db->model('Person'); $FacebookUser =& $db->model('FacebookUser'); if (empty($prefix) && in_array('invites', $db->tables)) { $Invite =& $db->model('Invite'); $result = $Invite->find_by('nickname', (string) $user->user->name); if (!$result) { trigger_error('Sorry, you have not been invited yet ' . environment('email_from'), E_USER_ERROR); } } $faceuser = $FacebookUser->find_by('facebook_id', $_SESSION['fb_userid']); // a) facebook user exists, does not have a profile_id // b) facebook user exists, HAS a profile_id // c) facebook user does not exist if ($faceuser) { if (!$faceuser->profile_id) { $i = make_identity($values); if (!$i) { trigger_error('sorry I was unable to create an identity', E_USER_ERROR); } $faceuser->set_value('profile_id', $i->id); $faceuser->save_changes(); if (!$faceuser) { trigger_error('sorry I was unable to create a facebook user', E_USER_ERROR); } } else { // b $i = $Identity->find($faceuser->profile_id); if (!$i) { trigger_error('sorry I was unable to find the identity', E_USER_ERROR); } } } else { // c $i = make_identity($values); if (!$i) { trigger_error('sorry I was unable to create an identity', E_USER_ERROR); } $faceuser = make_fb_user($user, $i->id); if (!$faceuser) { trigger_error('sorry I was unable to create a facebook user', E_USER_ERROR); } } $_SESSION['fb_person_id'] = $i->person_id; redirect_to($request->base); //$fs->setStatus("nerding out with the latest Facebook API tools",$_SESSION['fb_userid']); //$fs->StreamRequest( $app_id, $_SESSION['fb_session'], $_SESSION['fb_userid'] ); }
* 'returned': The user has authorize the app on Facebook */ switch ($state) { default: $fs = new FacebookStream($consumer_key, $consumer_secret, $agent); $token = $fs->getAccessToken(); /* Save token for later */ $_SESSION['fb_request_token'] = $token; $url = 'http://www.facebook.com/login.php?api_key='; $url .= $fs->getApiKey(); $url .= '&v=1.0&auth_token='; $url .= $token; header('Location:' . $url); exit; case 'returned': $fs = new FacebookStream($consumer_key, $consumer_secret, $agent); /* If the access tokens are already set skip to the API call */ if ($_SESSION['fb_session'] === NULL && $_SESSION['fb_userid'] === NULL) { /* Create session */ $session = $fs->getSession($_SESSION['fb_request_token']); /* Save the session data */ $_SESSION['fb_session'] = (string) $session->session_key; $_SESSION['fb_userid'] = (string) $session->uid; } //$fs->setStatus("updating my status with my new php library called Facebook Streams",$_SESSION['fb_userid']); $fs->StreamRequest($app_id, $_SESSION['fb_session'], $_SESSION['fb_userid']); } ?> <html> <head>
* 'returned': The user has authorize the app on Facebook */ switch ($state) { default: $fs = new FacebookStream($consumer_key, $consumer_secret, $agent); $token = $fs->getAccessToken(); /* Save token for later */ $_SESSION['fb_request_token'] = $token; $url = 'http://www.facebook.com/login.php?api_key='; $url .= $fs->getApiKey(); $url .= '&v=1.0&auth_token='; $url .= $token; header('Location:' . $url); exit; case 'returned': $fs = new FacebookStream($consumer_key, $consumer_secret, $agent); if (!empty($infinite_session) && $_SESSION['fb_userid'] > 0) { /* Infinite session, headless mode, use FB UserID from database to skip to the API call */ $fs->streamRequest($_SESSION['fb_userid']); } elseif ($_SESSION['fb_session'] === NULL && $_SESSION['fb_userid'] === NULL) { /* If the access tokens are already set skip to the API call */ /* Create session */ $session = $fs->getSession($_SESSION['fb_request_token']); /* Save the session data */ $_SESSION['fb_session'] = (string) $session->session_key; $_SESSION['fb_userid'] = (string) $session->uid; } if (isset($_GET['key'])) { $fs->permanent_facebook_key($consumer_key, $consumer_secret); } //$fs->setStatus("updating my status with my new php library called Facebook Streams",$_SESSION['fb_userid']);
} global $db, $prefix; if (environment('facebookSession')) { $app_id = environment('facebookAppId'); $consumer_key = environment('facebookKey'); $consumer_secret = environment('facebookSecret'); $agent = environment('facebookAppName') . " (curl)"; add_include_path(library_path()); add_include_path(library_path() . 'facebook-platform/php'); add_include_path(library_path() . 'facebook_stream'); require_once "FacebookStream.php"; require_once "Services/Facebook.php"; require_once "facebook.php"; $sesskey = environment('facebookSession'); $fb = new Facebook($consumer_key, $consumer_secret, true); $fs = new FacebookStream($consumer_key, $consumer_secret, $agent); // $fs = new FacebookStream($consumer_key,$consumer_secret,$agent); $fb->api_client->session_key = $sesskey; } $FacebookUser =& $db->model('FacebookUser'); $Post =& $db->model('Post'); $Identity =& $db->model('Identity'); foreach ($follow as $uid => $options) { if (!$options[1]['person_id']) { continue; } $microblog = $Setting->find_by(array('person_id' => $options[1]['person_id'], 'name' => 'tweetiepic_stream')); if (!$microblog) { continue; } if (substr($options[0], 9, 14) == 'importfacebook' && environment('facebookSession')) {