public function callback($provider = 'apontador') { $redir = Session::read('redir'); $redir = empty($redir) ? '/settings' : $redir; if ($provider == 'foursquare') { $code = $_GET["code"]; $callbackurl = ROOT_URL . "oauth/callback/foursquare"; $api = new FourSquareApiV2(\FOURSQUARE_CONSUMER_KEY, \FOURSQUARE_CONSUMER_SECRET, $callbackurl); $access_token = $api->accessToken($code); $user_info = $api->getUser(); Session::write('foursquareToken', $access_token); Session::write('foursquareName', $user_info['name']); Session::write('foursquarePhoto', $user_info['photo']); Session::write('foursquareEmail', $user_info['email']); } elseif ($provider == 'twitter') { $verifier = $_GET['oauth_verifier']; $twitterToken = Session::read('twitterToken'); $twitterTokenSecret = Session::read('twitterTokenSecret'); $api = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $twitterToken, $twitterTokenSecret); $access_token = $api->getAccessToken($verifier); Session::write('twitterUserId', $access_token['user_id']); Session::write('twitterName', $access_token['screen_name']); Session::write('twitterToken', $access_token['oauth_token']); Session::write('twitterTokenSecret', $access_token['oauth_token_secret']); } elseif ($provider == 'facebook') { $api = new Facebook(array('appId' => \FACEBOOK_AP_ID, 'secret' => \FACEBOOK_SECRET, 'cookie' => true)); $session = $api->getSession(); $userInfo = $api->api('/me'); Session::write('facebookToken', $session['access_token']); Session::write('facebookSig', $session['sig']); Session::write('facebookUid', $session['uid']); Session::write('facebookName', $userInfo['name']); } elseif ($provider == 'orkut') { $verifier = $_GET['oauth_verifier']; $oauthToken = $_GET['oauth_token']; $orkutToken = Session::read('orkutToken'); $orkutTokenSecret = Session::read('orkutTokenSecret'); $api = new OrkutOAuth(\ORKUT_CONSUMER_KEY, \ORKUT_CONSUMER_SECRET, $orkutToken, $orkutTokenSecret); $access_token = $api->getAccessToken($verifier, $oauthToken); $userInfo = $api->get("http://www.orkut.com/social/rest/people/@me/@self"); $userName = $userInfo->entry->name->givenName . ' ' . $userInfo->entry->name->familyName; Session::write('orkutUserId', $userInfo->entry->id); Session::write('orkutName', $userName); Session::write('orkutToken', $access_token['oauth_token']); Session::write('orkutTokenSecret', $access_token['oauth_token_secret']); } elseif ($provider == 'apontador') { $api = new ApontadorApi(); $token = $api->apontadorProcessaAutorizacao(); $userInfo = $api->getUser(array('userid' => $token['user_id'])); Session::write('apontadorToken', $token['oauth_token']); Session::write('apontadorTokenSecret', $token['oauth_token_secret']); Session::write('apontadorId', $token['user_id']); Session::write('apontadorName', $userInfo->getName()); } Session::delete('redir'); $this->redirect($redir); }
private function doFoursquareCheckin($checkinData = '') { $callbackurl = ROOT_URL . "oauth/callback/foursquare"; $foursquareApi = new FourSquareApiV2(\FOURSQUARE_CONSUMER_KEY, \FOURSQUARE_CONSUMER_SECRET, $callbackurl); $foursquareApi->setOAuth2Token(Session::read('foursquareToken')); if (!empty($checkinData['radius_mt'])) { $radius_mt = $checkinData['radius_mt']; } else { $radius_mt = 1000; } if (!empty($checkinData['lat'])) { $lat = $checkinData['lat']; } else { $lat = '-23.5934'; } if (!empty($checkinData['lng'])) { $lng = $checkinData['lng']; } else { $lng = '-46.6876'; } if (!empty($checkinData['placeName'])) { $term = $checkinData['placeName']; } else { $term = ''; } $limit = 5; $intent = 'checkin'; // checkin ou match $venues = $foursquareApi->searchVenues($lat, $lng, $radius_mt, $term, $limit, $intent); if (!empty($venues)) { $checkinData['placeId'] = $venues[0]['id']; $checkinData['placeName'] = $venues[0]['name']; $checkin = $foursquareApi->checkinVenue($checkinData['placeId'], $checkinData['status'], 'public'); } }