【问题标题】:Error pulling companies user is admin of in LinkedIn错误拉公司用户是 LinkedIn 的管理员
【发布时间】:2017-12-25 11:41:12
【问题描述】:

我目前正在尝试使用 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


    【解决方案1】:

    我发现了问题。

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

    我的固定代码如下:

    来电:

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

    【讨论】:

      【解决方案2】:

      首先你必须得到linkedin用户的用户令牌 使用Socialiteoauth 的REST API 包。

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

      $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 公司资料列表数组。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-20
        • 2023-03-09
        • 2018-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-26
        • 2015-08-28
        相关资源
        最近更新 更多