Exemple #1
0
 public function auth()
 {
     $linkedIn = new Happyr\LinkedIn\LinkedIn(LI_CLIENT_ID, LI_SECRET_KEY);
     if ($linkedIn->isAuthenticated()) {
         $access_token = $linkedIn->getAccessToken();
         $user = $linkedIn->get('v1/people/~:(id)');
         $user_account = array('user_id' => $this->user->id, 'account_id' => $user['id'], 'type' => 'linkedin', 'access_token' => $access_token->getToken());
         $this->load->model('user_account_model');
         if ($this->user_account_model->save($user_account)) {
             redirect(base_url() . "main/myaccount/linkedin");
         }
     }
     exit("Something went wrong.");
 }
Exemple #2
0
 public function linkedin_verify_access_key($user)
 {
     $result['has_valid_access_token'] = false;
     $CI =& get_instance();
     $CI->load->model('user_account_model');
     $linkedin_accounts = $CI->user_account_model->get(array('user_id' => $user->id, 'type' => 'linkedin'));
     $result['accounts'] = array();
     if (sizeof($linkedin_accounts) > 0) {
         foreach ($linkedin_accounts as $account) {
             $result['has_valid_access_token'] = true;
             $linkedIn = new Happyr\LinkedIn\LinkedIn(LI_CLIENT_ID, LI_SECRET_KEY);
             $linkedIn->setAccessToken($account->access_token);
             $a['user_info'] = $linkedIn->get('v1/people/~:(id,first-name,last-name,formatted-name,picture-url)');
             $a['id'] = $account->id;
             $result['accounts'][] = $a;
         }
     }
     $linkedIn = new Happyr\LinkedIn\LinkedIn(LI_CLIENT_ID, LI_SECRET_KEY);
     $result['auth_url'] = $linkedIn->getLoginUrl(array('redirect_uri' => LI_CALLBACK));
     return $result;
 }