0

我使用以下功能通过公共 API 导入我的用户链接信息。

除了数组的“位置”之外,所有数据都正确导入。

导入职位的正确方法是什么?

function getUserProfile()
    {
        try{
            // http://developer.linkedin.com/docs/DOC-1061
            $response = $this->api->profile('~:(id,first-name,last-name,public-profile-url,picture-url,picture-urls::(original),email-address,headline,summary,location,industry,positions)');
        }
        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 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->industry    = (string) $data->{'industry'};
            $this->user->profile->location    = (string) $data->location->name;
            $this->user->profile->summary    = (string) $data->{'summary'};

            $this->user->profile->positionTitle    = (array) $data->position->title;

            $this->user->profile->email         = (string) $data->{'email-address'};
            $this->user->profile->emailVerified = (string) $data->{'email-address'};

            $this->user->profile->photoURL    = (string) $data->{'picture-url'};
            $this->user->profile->profileURL  = (string) $data->{'public-profile-url'};
            $this->user->profile->description = (string) $data->{'headline'};

            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;
            }

            if( (string) $data->{'picture-urls'}->{'picture-url'} ){ 
                $this->user->profile->photoURL  = (string) $data->{'picture-urls'}->{'picture-url'};
            }

            return $this->user->profile;
        }
        else{
            throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
        }
    }
4

0 回答 0