2017-08-08 6 views
1

私はこのguide以下とされてきたのOAuth V2.0でAPIをLinkedInのからのアクセストークンを取得するために管理することはできません私は、PHP 7.1.7を使用してaccess_tokenはを取得し、カールするには、次の要求をしたことが言及として

function httpRequest($url, $auth_header, $method, $body = NULL){ 

    if (!$method){$method = "GET";} 
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_HEADER, 0); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header)); // Set the headers. 

    if ($body) { 
     curl_setopt($curl, CURLOPT_POST, 1); 
     curl_setopt($curl, CURLOPT_POSTFIELDS, $body); 
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); 
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded")); 
    } 
    $data = curl_exec($curl); 
    curl_close($curl); 
    return $data; 
} 

それから私はこのようなPOSTリクエストします:私はことを知っている

$post_data = httpRequest("www.linkedin.com/oauth/v2/accessToken",$auth_header, "POST", $body); 

$auth_header = null; 
$code = $_GET['code']; 
$body = "grant_type=authorization_code&code=".$code."&redirect_uri=".$config['callback_url']."&client_id=".$config['linkedin_access']."&client_secret=".$config['linkedin_secret']; 

を私は、正しく認証コードを取得していますが、何らかの理由で私は

どちら

access_tokenは

ではなく

をexpires_in取得することができないんだけど、私は」次のエラーが発生する

{ "エラー": "https_required"、 "ましたerror_description": "クライアントが許可されていない"}予め

おかげ。

+0

を使用する必要があることを発見しました。 代わり $ post_data =のHttpRequest( "www.linkedin.com/oauth/v2/accessToken" ... それは $ post_data =のHttpRequest( "https://www.linkedin.com/oauth/v2/accessTokenする必要があります"... –

答えて