Beispiel #1
0
 /**
  * Function to post Message to Linkedin on various actions
  * @param array $userData
  * @param string $statusMessage
  * @author Rohan Julka
  * */
 public function postToLinkedin($userData, $statusMessage)
 {
     require_once ROOT . DS . APP_DIR . DS . 'Plugin/linkedin/linkedin.php';
     $ln = new LinkedIn(Configure::read('linkedinApiKey'), Configure::read('linkedinApiSecret'));
     $ln->setTokenData($userData['User']['linkedin_access_token']);
     //$user = $ln->fetch('GET', '/v1/people/~:(firstName,lastName)');
     //print "Hello $user->firstName $user->lastName.";
     try {
         $ln->fetch('POST', '/v1/people/~/shares', array('comment' => $statusMessage, 'visibility' => array('code' => 'anyone')));
     } catch (Exception $e) {
         $this->Session->setFlash('Unable to post to Linkedin', 'Front/flash_bad');
     }
 }
 /**
  * Function to linkedinPost
  * @author Rohan Julka
  * */
 public function linkedinPost()
 {
     require_once ROOT . DS . APP_DIR . DS . 'Plugin/linkedin/linkedin.php';
     $loginUserId = $this->Encryption->decode($this->Session->read('Auth.Front.id'));
     $userData = $this->User->userInfoById($loginUserId);
     $ln = new LinkedIn(Configure::read('linkedinApiKey'), Configure::read('linkedinApiSecret'));
     //$ln->addScope('rw_nus');
     //pr($ln->getTokenData());exit;
     $ln->setTokenData($userData['User']['linkedin_access_token']);
     $user = $ln->fetch('GET', '/v1/people/~:(firstName,lastName)');
     print "Hello {$user->firstName} {$user->lastName}.";
     print_r($ln->fetch('POST', '/v1/people/~/shares', array('comment' => 'Hello Linkedin', 'visibility' => array('code' => 'anyone'))));
     //Update stored token.
     $tokenData = $ln->getTokenData();
     pr($tokenData);
     exit;
 }