"会员0无权获得公司"尝试访问LinkedIn公司更新时出错

时间:2015-06-12 15:05:47

标签: php oauth linkedin linkedin-api

在我通过LinkedIn的开发人员后端创建我的应用程序后,我已经让客户批准我的用户作为管理员。我甚至让客户创建他们的OWN应用程序并为我提供客户端密钥,但是每次尝试提取公司更新时我都会收到相同的错误消息:

"会员0无权获得公司1311XXX"

以下是该页面的代码:

$config['base_url']             =   'http://www.hiddenlink.com/resources/li-oauth-src/auth.php';
$config['callback_url']         =   'http://www.hiddenlink.com/resources/li-oauth-src/demo.php';
$config['linkedin_access']      =   '770lXXXXXXXXXX';
$config['linkedin_secret']      =   'hcxpOtXXXXXXXXXX';

include_once "linkedin.php";

# First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;

if (isset($_REQUEST['oauth_verifier'])){
    $_SESSION['oauth_verifier']     = $_REQUEST['oauth_verifier'];

    $linkedin->request_token    =   unserialize($_SESSION['requestToken']);
    $linkedin->oauth_verifier   =   $_SESSION['oauth_verifier'];
    $linkedin->getAccessToken($_REQUEST['oauth_verifier']);

    $_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
    header("Location: " . $config['callback_url']);
    exit;
}
else{
    $linkedin->request_token    =   unserialize($_SESSION['requestToken']);
    $linkedin->oauth_verifier   =   $_SESSION['oauth_verifier'];
    $linkedin->access_token     =   unserialize($_SESSION['oauth_access_token']);
}

$json_response = $linkedin->getCompanyUpdates("1311XXX");
$json = json_decode($json_response);
echo "<pre>";
print_r($json);
echo "</pre>";

for($x = 0; $x < 2; $x++){
    $json_value = $json->values[$x];
    $articleURL = $json_value->updateContent->companyStatusUpdate->share->content->eyebrowUrl;
    $postTitle = $json_value->updateContent->companyStatusUpdate->share->content->title;
    $description = htmlspecialchars($json_value->updateContent->companyStatusUpdate->share->content->description);
    $timestamp = $json_value->updateContent->companyStatusUpdate->share->timestamp;
    echo '<pre>';
    print_r($description);
    echo '<br />';
    print_r($articleURL);
    echo '<br />';
    print_r($postTitle);
    print_r(date("jS M, Y", $timestamp));
    echo '</pre>';
}

以下是为json_response变量调用getCompanyUpdates函数的代码:

function getCompanyUpdates($id){
    $updateURL = $this->base_url . "/v1/companies/" . $id . "/updates?format=json";
    $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $updateURL);
    $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
    $auth_header = $request->to_header("https://api.linkedin.com"); # this is the realm
    $response = $this->httpRequest($updateURL, $auth_header, "GET");
    return $response;
}

我不知道自己做错了什么,但很清楚我做错了什么。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您似乎没有在oauth工作流程中的任何位置明确传递范围值,因此我只能假设您依赖于LinkedIn应用程序的默认范围值来正确配置。

检查以确保在尝试进行API调用时请求rw_company_admin成员权限。