public function twitterCallback()
 {
     //echo "helloCallback";
     if (!empty($_GET['oauth_verifier']) && !empty($this->request->session()->read('oauth_token')) && !empty($this->request->session()->read('oauth_token_secret'))) {
         $connection = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $this->request->session()->read('oauth_token'), $this->request->session()->read('oauth_token_secret'));
         $access_tokencredential = $connection->getAccessToken($_REQUEST['oauth_verifier'], $this->request->session()->read('oauth_token'));
         $uniqueOauthToken = $access_tokencredential['oauth_token'];
         $uniqueOauthTokenSecret = $access_tokencredential['oauth_token_secret'];
         $twitteroauth = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $uniqueOauthToken, $uniqueOauthTokenSecret);
         $message = "Tweet From Panovus Team!";
         //$output = $twitteroauth->get('friends/list');
         //$output = $twitteroauth->post("statuses/update", array("status" => $message));
         //echo"<pre style='color:red'>";
         //print_r($output);
         //echo'</pre>';
         /*
         echo"<pre style='color:red'>";
         print_r($access_tokencredential);
         		echo "</pre>";
         */
         //return $output;
         $id = $this->Auth->user('partner_id');
         $partner = $this->Partners->get($id);
         $data = ["twitter_oauth_token" => $uniqueOauthToken, "twitter_oauth_token_secret" => $uniqueOauthTokenSecret];
         $partner = $this->Partners->patchEntity($partner, $data);
         //echo "<pre style='color:red'>";
         //print_r($partner);
         //echo "</pre>";
         if ($this->Partners->save($partner)) {
             $this->Flash->success('Token has been saved.');
             return $this->redirect(['controller' => 'PartnerCampaignEmailSettings']);
         } else {
             $this->Flash->error('The partner could not be saved. Please try again. If you continue to experience problems, please contact Customer Support.');
         }
     } else {
         //end if get
         $this->Flash->error('Authorization has failed!');
         return $this->redirect(['controller' => 'PartnerCampaignEmailSettings']);
     }
 }
Beispiel #2
0
 function test()
 {
     if (!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])) {
         // We've got everything we need
         // TwitterOAuth instance, with two new parameters we got in twitter_login.php
         $twitteroauth = new TwitterOAuth('YOUR_CONSUMER_KEY', 'YOUR_CONSUMER_SECRET', $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
         // Let's request the access token
         $access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);
         // Save it in a session var
         $_SESSION['access_token'] = $access_token;
         // Let's get the user's info
         $user_info = $twitteroauth->get('account/verify_credentials');
         // Print user's info
         print_r($user_info);
     } else {
         // Something's missing, go back to square 1
         redirect("client/");
         echo "missing";
         die;
         //header('Location: twitter_login.php');
     }
 }