I'm trying to get vanityName so I can concatenate with LinkedIn's URL to make the public profile URL, but I can only get some other fields, like lastname, email, id, etc.
I'm setting 'scope' => 'r_basicprofile'
, but I'm not sure if I'm putting it in the right place.
Already tried to set 'scope' => 'r_basicprofile'
inside $provider = new LinkedIn([...])
and inside $options:
$options = [
'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
'scope' => ['r_liteprofile','r_emailaddress']
];
$authorizationUrl = $provider->getAuthorizationUrl($options);
What am I doing wrong?
Code:
public function setLinkedin(Request $request)
{
$provider = new LinkedIn([
'clientId' => 'clientIdHere',
'clientSecret' => 'clientSecretHere',
'redirectUri' => 'http://' . $request->getHost() . ':' . $request->getPort() . $this->generateUrl('vincular_linkedin'),
'scope' => 'r_basicprofile'
]);
if (!$request->get('code')) {
$authUrl = $provider->getAuthorizationUrl();
$this->get('session')->set('oauth2state', $provider->getState());
header('Location: ' . $authUrl);
exit;
} elseif (!$request->get('state') || ($request->get('state') !== $this->get('session')->get('oauth2state'))) {
$this->get('session')->remove('oauth2state');
exit('Invalid state');
} else {
$token = $provider->getAccessToken('authorization_code', [
'code' => $request->get('code')
]);
try {
$user = $provider->getResourceOwner($token);
echo '<pre>';
var_dump($user);
echo '</pre>';
} catch (Exception $e) {
exit ($e);
}
}
return new Response();
}
I'm following this and this link.
Using Symfony 4.3.3 with PHP 7+.
My app is already registered, but I only have three permissions: r_emailaddress, r_liteprofile and w_member_social. I can't change it.
Installed LinkedIn API via composer.