使用zoonman / linkedin-api-php-client从LinkedIn API V2获取完整的r_basicprofile信息

时间:2018-12-17 19:36:36

标签: php linkedin linkedin-api

我正在使用此PHP SDK连接到LinkedIn API:

https://github.com/zoonman/linkedin-api-php-client

我正在这样验证:

    // define client
    $client = new Client(
        $_ENV["YOUR_LINKEDIN_APP_CLIENT_ID"],
        $_ENV["YOUR_LINKEDIN_APP_CLIENT_SECRET"]
    );
    $client->setRedirectUrl($_ENV["YOUR_LINKEDIN_APP_REDIRECT"]);
    $client->setApiRoot('https://api.linkedin.com/v2/');

    // define scope
    $scopes = ['r_liteprofile','r_basicprofile','r_emailaddress'];

    // redirect to LinkedIn
    $loginUrl = $client->getLoginUrl($scopes);
    return(redirect($loginUrl));

通过身份验证后,我将请求“ me”端点,如下所示:

   if (isset($_GET['code'])):
        $client = new Client(
            $_ENV["YOUR_LINKEDIN_APP_CLIENT_ID"],
            $_ENV["YOUR_LINKEDIN_APP_CLIENT_SECRET"]
        );
        $client->setRedirectUrl($_ENV["YOUR_LINKEDIN_APP_REDIRECT"]);
        $client->setApiRoot('https://api.linkedin.com/v2/');

        // get access token and store in session
        $accessToken = $client->getAccessToken($_GET['code']);
        $_SESSION["accessToken"]=$accessToken;
        $client->setAccessToken($accessToken);

        // get user profile
        $profile = $client->get('me');
        print '<pre>';
        print_r($profile);
        print '</pre>';
    endif;

我的答复仅包括以下内容:

    Array
(
    [lastName] => Array
        (
            [localized] => Array
                (
                    [en_US] => Blow
                )

            [preferredLocale] => Array
                (
                    [country] => US
                    [language] => en
                )

        )

    [firstName] => Array
        (
            [localized] => Array
                (
                    [en_US] => Joe
                )

            [preferredLocale] => Array
                (
                    [country] => US
                    [language] => en
                )

        )

    [profilePicture] => Array
        (
            [displayImage] => urn:li:digitalmediaAsset:12345678
        )

    [id] => 1234567
)

我没有获得我有权请求的所有数据:

https://developer.linkedin.com/docs/fields/basic-profile

我在做什么错了?

我如何访问所有其他字段?

1 个答案:

答案 0 :(得分:0)

您必须使用API​​ v2字段和方法。试试这个:

$client->get('me?projection=(id,firstName,lastName,profilePicture,headline)');

为了访问某些字段,您可能需要请求更多权限。查看此链接以获取更多信息:

https://docs.microsoft.com/en-us/linkedin/shared/integrations/people/profile-api#field-selections https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile#profile-fields-available-with-linkedin-partner-programs