Hybrid_Providers_LinkedIn::getUserProfile PHP Méthode

getUserProfile() public méthode

public getUserProfile ( )
    function getUserProfile()
    {
        try {
            // http://developer.linkedin.com/docs/DOC-1061
            $response = $this->api->profile('~:(' . implode(',', $this->config['fields']) . ')');
        } catch (LinkedInException $e) {
            throw new Exception("User profile request failed! {$this->providerId} returned an error: {$e->getMessage()}", 6, $e);
        }
        if (isset($response['success']) && $response['success'] === true) {
            $data = @new SimpleXMLElement($response['linkedin']);
            if (!is_object($data)) {
                throw new Exception("User profile request failed! {$this->providerId} returned an invalid xml data: " . Hybrid_Logger::dumpData($data), 6);
            }
            $this->user->profile->identifier = (string) $data->{'id'};
            $this->user->profile->firstName = (string) $data->{'first-name'};
            $this->user->profile->lastName = (string) $data->{'last-name'};
            $this->user->profile->displayName = trim($this->user->profile->firstName . " " . $this->user->profile->lastName);
            $this->user->profile->email = (string) $data->{'email-address'};
            $this->user->profile->emailVerified = (string) $data->{'email-address'};
            if ($data->{'positions'}) {
                $this->user->profile->job_title = (string) $data->{'positions'}->{'position'}->{'title'};
                $this->user->profile->organization_name = (string) $data->{'positions'}->{'position'}->{'company'}->{'name'};
            }
            if (isset($data->{'picture-url'})) {
                $this->user->profile->photoURL = (string) $data->{'picture-url'};
            } elseif (isset($data->{'picture-urls'})) {
                // picture-urls::(original)
                $this->user->profile->photoURL = (string) $data->{'picture-urls'}->{'picture-url'};
            } else {
                $this->user->profile->photoURL = "";
            }
            $this->user->profile->profileURL = (string) $data->{'public-profile-url'};
            $this->user->profile->description = (string) $data->{'summary'};
            if ($data->{'phone-numbers'} && $data->{'phone-numbers'}->{'phone-number'}) {
                $this->user->profile->phone = (string) $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'};
            } else {
                $this->user->profile->phone = null;
            }
            if ($data->{'date-of-birth'}) {
                $this->user->profile->birthDay = (string) $data->{'date-of-birth'}->day;
                $this->user->profile->birthMonth = (string) $data->{'date-of-birth'}->month;
                $this->user->profile->birthYear = (string) $data->{'date-of-birth'}->year;
            }
            return $this->user->profile;
        } else {
            throw new Exception("User profile request failed! {$this->providerId} returned an invalid response: " . Hybrid_Logger::dumpData($response), 6);
        }
    }

Usage Example

Exemple #1
0
 /**
  * load the user profile from the IDp api client
  */
 function getUserProfile()
 {
     parent::getUserProfile();
     try {
         // https://developer.linkedin.com/docs/signin-with-linkedin
         $response = $this->api->profile('~:(id,positions,location,industry)');
     } catch (\LinkedInException $e) {
         throw new \Exception("User profile request failed! {$this->providerId} returned an error: {$e}", 6);
     }
     if (isset($response['success']) && $response['success'] === true) {
         $data = @new \SimpleXMLElement($response['linkedin']);
         if (!is_object($data)) {
             throw new \Exception("User profile request failed! {$this->providerId} returned an invalid xml data.", 6);
         }
         if ($data->{'positions'}) {
             $positions = $data->{'positions'};
             $attributes = $data->{'positions'}->attributes();
             if (isset($attributes['total']) && (int) $attributes['total'] > 0) {
                 foreach ($positions->{'position'} as $position) {
                     if ((string) $position->{'is-current'} == 'true') {
                         $this->user->profile->position = (string) $position->title;
                         if ($position->company) {
                             $this->user->profile->company = (string) $position->company->name;
                         }
                         $this->user->profile->position = (string) $position->title;
                     }
                 }
             }
         }
         if ($data->{'industry'}) {
             $this->user->profile->industry = (string) $data->{'industry'};
         }
         if ($data->{'location'}) {
             $location = $data->{'location'};
             $this->user->profile->city = (string) $location->name;
         }
         return $this->user->profile;
     } else {
         throw new \Exception("User profile request failed! {$this->providerId} returned an invalid response.", 6);
     }
 }