function explore_venues($data) { $foursquare_obj = new EpiFoursquare($this->client_id, $this->client_secret); return $foursquare_obj->get('/venues/explore', $data); }
$redirectUri = 'http://server.neatocode.com/spaceneedle/simpleTest.php'; //$userId = '5763863'; $fsObj = new EpiFoursquare($clientId, $clientSecret, $accessToken); $fsObjUnAuth = new EpiFoursquare($clientId, $clientSecret); $example_images = array('http://server.neatocode.com/spaceneedle/example_desert.png', 'http://server.neatocode.com/spaceneedle/example_drinks.png', 'http://server.neatocode.com/spaceneedle/example_food.png'); $ll = "36.060944,-115.133735"; // Default to the Venetian. if (htmlspecialchars($_GET["ll"])) { $ll = htmlspecialchars($_GET["ll"]); } $item = 0; // Default to item 0. if (htmlspecialchars($_GET["item"])) { $item = htmlspecialchars($_GET["item"]); } $venue = $fsObjUnAuth->get('/venues/explore', array('ll' => $ll, 'venuePhotos' => 1)); $items = $venue->response->groups[0]->items; $default_reason = $venue->response->groups[0]->items[0]->reasons->items[0]->message; $first_item = true; $count = 0; $item = $items[$item]; //foreach ($items as &$item) { if (!$item) { ?> { "name" : "Nothing now. Keep looking!", "lat" : null, "lon" : null, "distance" : 0, "image" : null, }
/** * displayFoursquareSubmit * * The submit screen for saving foursquare data. * * @return void */ function displayFoursquareSubmit() { $r = getFoursquareConfigData(); $id = cleanOutput($r['fs_client_id']); $secret = cleanOutput($r['fs_client_secret']); $url = cleanOutput($r['fs_callback_url']); $fsObj = new EpiFoursquare($id, $secret); $token = $fsObj->getAccessToken($_GET['code'], $url); $fsObjAuth = new EpiFoursquare($id, $secret, $token->access_token); $self = $fsObjAuth->get('/users/self'); $sql = "UPDATE `fcms_user_settings`\n SET `fs_user_id` = ?,\n `fs_access_token` = ?\n WHERE `user` = ?"; $params = array($self->response->user->id, $token->access_token, $this->fcmsUser->id); if (!$this->fcmsDatabase->update($sql, $params)) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } header("Location: settings.php?view=foursquare"); }
echo $authorizeUrl; ?> </a> <?php } else { ?> <h2>Display your own badges</h2> <?php if (!isset($_COOKIE['access_token'])) { $token = $fsObjUnAuth->getAccessToken($_GET['code'], $redirectUri); setcookie('access_token', $token->access_token); $_COOKIE['access_token'] = $token->access_token; } $fsObjUnAuth->setAccessToken($_COOKIE['access_token']); $badges = $fsObjUnAuth->get('/users/self/badges'); ?> <pre><?php var_dump($badges->response); ?> </pre> <?php } ?> <hr> <h2>Get a test user's checkins</h2> <?php $creds = $fsObj->get("/users/{$userId}/checkins"); ?>
/** * * * @return array */ function foursquare() { App::import("Vendor", "Users.foursquare/EpiCurl"); App::import("Vendor", "Users.foursquare/EpiFoursquare"); $response = array(); $foursquareObj = new EpiFoursquare(FOURSQUARE_CLIENT_ID, FOURSQUARE_CLIENT_SECRET); $redirectUri = Router::url(array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'foursquare'), true); if (!isset($_GET['code']) && !isset($_SESSION['fs_access_token'])) { $url = $foursquareObj->getAuthorizeUrl($redirectUri); $response['url'] = $url; } else { if (!isset($_SESSION['fs_access_token'])) { $token = $foursquareObj->getAccessToken($_GET['code'], $redirectUri); //setcookie('fs_access_token', $token->access_token); $_SESSION['fs_access_token'] = $token->access_token; } $foursquareObj->setAccessToken($_SESSION['fs_access_token']); $foursquareInfo = $foursquareObj->get('/users/self'); $user_profile = (array) $foursquareInfo->response; $fsToken = $_SESSION['fs_access_token']; } $response['user_profile'] = isset($user_profile) ? $user_profile : ''; $response['user_profile']['accessToken'] = isset($fsToken) ? $fsToken : ''; return $response; }
<h1>Simple test to make sure everything works ok</h1> <h2><a href="javascript:void(0);" onclick="viewSource();">View the source of this file</a></h2> <div id="source" style="display:none; padding:5px; border: dotted 1px #bbb; background-color:#ddd;"> <?php highlight_file(__FILE__); ?> </div> <hr> <h2>Test an unauthenticated call to search for a venue</h2> <?php $venue = $fsObjUnAuth->get('/venues/explore', array('ll' => '40.7,-74', 'venuePhotos' => "1")); ?> <pre><?php var_dump($venue->response->groups[0]->items[0]); ?> </pre> <hr> <?php if (!isset($_GET['code']) && !isset($_COOKIE['access_token'])) { ?> <h2>Generate the authorization link</h2> <?php $authorizeUrl = $fsObjUnAuth->getAuthorizeUrl($redirectUri); ?>
<p>' . T_('The "Where Is Everyone" feature cannot work without Foursquare. Please configure Foursquare or turn off "Where Is Everyone".') . '</p> </div>'; } // we continue on, because we still might be able to show user data (if they have an access token) // this would happen if foursquare was setup, users granted access, then foursquare was removed. } $historyData = array(); $i = 0; foreach ($users as $k => $data) { // Skip users who don't have foursquare setup if (empty($data['access_token'])) { continue; } $fsObj = new EpiFoursquare($config['fs_client_id'], $config['fs_client_secret'], $data['access_token']); try { $creds = $fsObj->get('/users/' . $data['user_id'] . '/checkins'); } catch (EpiFoursquareException $e) { echo 'We caught an EpiOAuthException'; echo $e->getMessage(); break; } catch (Exception $e) { echo 'We caught an unexpected Exception'; echo $e->getMessage(); break; } $photo = getAvatarPath($data['avatar'], $data['gravatar']); foreach ($creds->response->checkins->items as $checkin) { // Skip shouts, etc if ($checkin->type != 'checkin') { continue; }
<h1>Simple test to make sure everything works ok</h1> <h2><a href="javascript:void(0);" onclick="viewSource();">View the source of this file</a></h2> <div id="source" style="display:none; padding:5px; border: dotted 1px #bbb; background-color:#ddd;"> <?php highlight_file(__FILE__); ?> </div> <hr> <h2>Test an unauthenticated call to search for a venue</h2> <?php $venue = $fsObjUnAuth->get('/venues/search', array('ll' => '40.7,-74')); ?> <pre><?php var_dump($venue->response->groups[0]->items[0]); ?> </pre> <hr> <?php if (!isset($_GET['code']) && !isset($_COOKIE['access_token'])) { ?> <h2>Generate the authorization link</h2> <?php $authorizeUrl = $fsObjUnAuth->getAuthorizeUrl($redirectUri); ?>
/** * getFoursquareWhatsNewData * * Adds foursquare data to the whats new data array. * * @param array $whatsNewData * * @return mixed - array on success or false on failure */ function getFoursquareWhatsNewData($whatsNewData) { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $fcmsUser = User::getInstance($fcmsError, $fcmsDatabase); include_once 'socialmedia.php'; include_once 'thirdparty/foursquare/EpiFoursquare.php'; include_once 'thirdparty/foursquare/EpiCurl.php'; $users = getFoursquareUsersData(); $config = getFoursquareConfigData(); // TODO // Move this check inside the getFoursquareConfigData and have it return false on failure. // Foursquare hasn't been setup or is invalid if (empty($config['fs_client_id']) or empty($config['fs_client_secret'])) { // If admin is viewing, alert them that the config is missing/messed up if ($fcmsUser->access < 2) { echo ' <div class="info-alert"> <h2>' . T_('Foursquare is not configured correctly.') . '</h2> <p>' . T_('The "Where Is Everyone" feature cannot work without Foursquare. Please configure Foursquare or turn off "Where Is Everyone".') . '</p> <p><a href="admin/foursquare.php">' . T_('Configure Foursquare') . '</a></p> <p><a href="admin/config.php?view=plugins">' . T_('Turn Off "Where is Everyone"') . '</a></p> </div>'; } return $whatsNewData; } $foursquareData = array(); if (count($users[0]) > 0) { $timeago = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y')); $i = 0; foreach ($users as $k => $data) { // Skip users who don't have foursquare setup if (empty($data['access_token'])) { continue; } $fsObj = new EpiFoursquare($config['fs_client_id'], $config['fs_client_secret'], $data['access_token']); try { $params = array('afterTimestamp' => $timeago); $creds = $fsObj->get('/users/' . $data['user_id'] . '/checkins', $params); } catch (EpiFoursquareException $e) { echo 'We caught an EpiOAuthException'; echo $e->getMessage(); return false; } catch (Exception $e) { echo 'We caught an unexpected Exception'; echo $e->getMessage(); return false; } foreach ($creds->response->checkins->items as $checkin) { // Skip shouts, etc if ($checkin->type != 'checkin') { continue; } $date = date('Y-m-d H:i:s', $checkin->createdAt); $sort = $checkin->createdAt; $shout = isset($checkin->shout) ? $checkin->shout : ''; // Save data $whatsNewData[] = array('id' => '', 'date' => $date, 'title' => $checkin->venue->name, 'userid' => $data['fcms_user_id'], 'id2' => $shout, 'id3' => '', 'type' => 'WHEREISEVERYONE'); } } } // Order is messed up now, so fix it $whatsNewData = subval_sort($whatsNewData, 'date'); $whatsNewData = array_reverse($whatsNewData); return $whatsNewData; }