Answer the question
In order to leave comments, you need to log in
How to solve oAuth issue using Linkedin API?
Hello. I decided to get data about the company from the Linkedin API. As a result, I got up on Access Token . Using the steps: https://developer.linkedin.com/docs/oauth2 stuck at 3.
My task now is to get a token, which I can't get for reasons I don't understand.
What I have:
1)
I got client_id and client_secret respectively. I set up the url on the linkedin side to http://demo.test/backend/linkedin.
2)
Collected the URL for authorization
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=725gqxsyeaz0dr&state=b0316f2ddd3a0af2b44efcff3f60836c&redirect_uri=http%3A%2F%2Fdemo.test%2Fbackend%2Flinkedin
grant_type=authorization_code&code=AQQ8POkuOe4TKjLrVaa34bz0HpMEk18Fohvqy9Dv9G6RoApogpDai_AN30QcD6_WTCNwxi4OjvMnZSDOzWjeotoNzFdMdK3hHvekCThothp6KoKq3F3h4dR37AaNOw3UduZ_DUfBwf-cQzt33ht32StJccNo_trFRtKfI-nw&redirect_uri=http%3A%2F%2Fdemo.test%2Fbackend%2Flinkedin&client_id=725gqxsyeaz0dr&client_secret=pxtGcphOs8feMXS0
grant_type=authorization_code&code=987654321&redirect_uri=https%3A%2F%2Fwww.myapp.com%2Fauth%2Flinkedin&client_id=123456789&client_secret=shhdonottell
AQQ8POkuOe4TKjLrVaa34bz0HpMEk18Fohvqy9Dv9G6RoApogpDai_AN30QcD6_WTCNwxi4OjvMnZSDOzWjeotoNzFdMdK3hHvekCThothp6KoKq3F3h4dR37AaNOw3UduZ_DUfBwf-cQzt33ht32StJccNo_trFRtKfI-nw
if (LinkedIn::isAuthenticated()) {
$url = parse_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
parse_str($url['query'], $url);
$code = $url['code'];
$data = [
"grant_type" => "authorization_code",
"code" => $code,
"redirect_uri" => "http://demo.test/backend/linkedin",
"client_id" => "725gqxsyeaz0dr",
"client_secret" => "pxtGcphOs8feMXS0"
];
$url2 = "https://www.linkedin.com/oauth/v2/accessToken";
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_URL, $url2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
$result_array = json_decode($result, true);
dump(http_build_query($data));
dump($result_array);
//we know that the user is authenticated now. Start query the API
//dd(LinkedIn::get('/v1/companies/11812834/updates?format=json'));
}elseif (LinkedIn::hasError()) {
echo "User canceled the login.";
exit();
}
//if not authenticated
$url = LinkedIn::getLoginUrl();
dump($url);
echo "<a href='$url'>Login with LinkedIn</a>";
exit();
}
array:2 [▼
"error" => "invalid_request"
"error_description" => "Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization code. Or authorization code expired. Or external member binding e ▶"
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question