如何使用linkedin v2 api获取电子邮件地址?

时间:2018-05-09 09:54:31

标签: php linkedin linkedin-api linkedin-jsapi

我无法通过linkedin v2 api获取用户的电子邮件地址。我在应用设置中添加了r_emailaddress权限,也在访问令牌请求中添加了权限。但它说。

{
"serviceErrorCode": 100,
"message": "Not enough permissions to access: GET-members /clientAwareMemberHandles",
"status": 403
}

我的请求网址是:

https://api.linkedin.com/v2/clientAwareMemberHandles?q=members&projection=(elements*(primary,type,handle~))&oauth2_access_token=".$token

任何人都可以帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

您可以使用以下EP访问访问用户的电子邮件地址:

`https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))`

确保已在库中定义了范围“ r_emailaddress”。

您可以使用下面的curl请求来获取数据:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Authorization: Bearer '. $token,
      'X-Restli-Protocol-Version: 2.0.0',
      'Accept: application/json',
      'Content-Type: application/json'
    ));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    $response = curl_exec($ch);
    $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $body = substr($response, $headerSize);
    $response_body = json_decode($body,true);

$ response_body将返回以下响应:

Array (
    [elements] => Array
        (
            [0] => Array
                (
                    [handle] => urn:li:emailAddress:123456
                    [handle~] => Array
                        (
                            [emailAddress] => your@email.in
                        )

                )

        )

)