예제 #1
0
 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);
 }
예제 #2
0
 private function doFacebookCheckin($checkinData = '')
 {
     $api = new Facebook(array('appId' => \FACEBOOK_AP_ID, 'secret' => \FACEBOOK_SECRET, 'cookie' => true));
     $session = array('access_token' => Session::read('facebookToken'), 'uid' => Session::read('facebookUid'), 'sig' => Session::read('facebookSig'));
     $api->setSession($session);
     try {
         $postStatus = $api->api('/me/feed', 'POST', array('message' => $checkinData['status'], 'access_token' => $facebookAccessToken));
     } catch (\Exception $e) {
         $postStatus = $e;
     }
 }