“file_get_contents”在Linux上工作正常但在Window上抛出错误401

时间:2015-10-06 06:54:53

标签: php linkedin linkedin-api

我尝试编写一个函数来获取已经过身份验证的LinkedIn用户的基本配置文件(我的意思是获得access_token)。

public function fetchLinkinProfile($method, $resource = '', $params = array(), $access_token) {
    if(empty($method)) $method = 'GET';
    if(empty($resource)){
        $resource = '/v1/people/~:(id,first-name,last-name,maiden-name,specialties,num-connections,picture-url,email-address,location:(name))';
    }

    $opts = array(
        'http' => array(
            'method' => $method,
            'header' => "Authorization: Bearer " .
                 $access_token . "\r\n" .
                "x-li-format: json\r\n"
        )
    );
    $url = 'https://api.linkedin.com' . $resource;
    if (count($params)) {
        $url .= '?' . http_build_query($params);
    }
    $context = stream_context_create($opts);
    $response = file_get_contents($url, false, $context);
    return json_decode($response);
}

此功能在Linux上运行良好,但在Window上它会抛出401 Unauthorized,尽管我在文件allow_url_fopen = ON中启用了php.ini。我错过了什么?

0 个答案:

没有答案