拉公司用户的错误是LinkedIn的管理员

问题描述 投票:0回答:2

我目前正试图通过LinkedIn API提取用户是管理员的公司页面列表,并得到以下响应:

Array
(
    [response] => {
  "errorCode": 0,
  "message": "Member does not have permission to get companies as admin.",
  "requestId": "R1LHP32UKD",
  "status": 403,
  "timestamp": 1482357250945
}
    [http_code] => 403
)

LinkedIn API Console中作为同一用户进行身份验证时,该调用非常有效。

还有其他人遇到过这个吗?

rest linkedin linkedin-api
2个回答
0
投票

我解决了这个问题。

即使我已确定应用程序已检查rw_company_admin权限,但在请求oauth2授权时,我没有在范围内传递该权限。

我的固定代码如下:

电话:

return $linkedin->getAuthorizationUrl("r_basicprofile w_share rw_company_admin", $thisurl);

功能:

public function getAuthorizationUrl($scope, $callback)
{
   $params = array('response_type' => 'code',
      'client_id' => $this->api_key,
      'scope' => $scope,
      'state' => uniqid('', true), // unique long string
      'redirect_uri' => $callback,
    );

    // Authentication request
    $url = 'https://www.linkedin.com/uas/oauth2/authorization?' . http_build_query($params);

    // Needed to identify request when it returns to us
    $_SESSION['Linkedin_state'] = $params['state'];
    $_SESSION['Linkedin_callback'] = $callback;

    // this is where to send the user
    return $url;
}

0
投票

首先,你必须获得linkedin用户的用户令牌使用Socialite或REST API包为oauth

获得用户令牌后,在管理员用户下获取公司列表非常简单

$token = 'uflefjefheilhfbwrfliehbwfeklfw';    // user token
$api_url = "https://api.linkedin.com/v1/companies?oauth2_access_token=".$token."&format=json&is-company-admin=true";
$pages = json_decode(file_get_contents($api_url));

你收到了$pages json的公司简介列表。

© www.soinside.com 2019 - 2024. All rights reserved.