Reputation: 101
I receive the error "Resource me does not exist" when I tried to call the URL GET: /v2/me.
GET: https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture)
Token received from: https://www.linkedin.com/oauth/v2/accessToken
Authorization URL:
$url = 'https://www.linkedin.com/oauth/v2/authorization'
.'?response_type=code'
.'&client_id='."77uuvjhz11mi71"
.'&redirect_uri='."http://localhost/linkedin"
.'&state=123123123'
.'&scope=r_liteprofile%20r_emailaddress%20w_member_social';
Request:
...
$linkedin->getAccessToken($_GET['code']);
...
$this->setMethod("GET");
$this->setUrl("https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture)");
$this->setHeaders([
"Authorization: Bearer ".$this->accessToken,
]);
$resp = $this->sendRequest();
Response:
{#81 ▼
+"serviceErrorCode": 0
+"message": "Resource me does not exist"
+"status": 404
}
The API functions:
public function __construct()
{
$this->ch = curl_init();
}
public function sendRequest()
{
curl_setopt_array($this->ch, $this->options);
$result = curl_exec($this->ch);
if (curl_errno($this->ch)) {
throw new Exception("Error ". curl_error($this->ch), 1);
}
$json = json_decode($result);
return $json;
}
public function setMethod(String $method)
{
$method = strtoupper($method);
if ($method === "POST") {
$this->options[CURLOPT_POST] = true;
}
return $this;
}
public function setUrl(String $url)
{
$this->options[CURLOPT_URL] = $url;
return $this;
}
public function setHeaders(Iterable $headers)
{
$this->options[CURLOPT_HTTPHEADER] = $headers;
return $this;
}
public function getAccessToken($code)
{
$this->setMethod("POST");
$this->setUrl("https://www.linkedin.com/oauth/v2/accessToken");
$this->setPostFields([
"grant_type" => "authorization_code",
"code" => $code,
"redirect_uri" => "http://localhost/test",
"client_id" => $this->clientId,
"client_secret" => $this->clientSecret,
]);
$resp = $this->sendRequest();
$this->accessToken = $resp->access_token;
}
Upvotes: 3
Views: 1771
Reputation:
The late response coming through,
I encountered a similar issue when making an API call to LinkedIn while using python and python's requests package. In my case, I solved the issue by using a GET request. I had been trying to make the API call using the POST request type which made the resource non-existent.
Here is a link to the docs, they've given an example of how the URL should look like: https://learn.microsoft.com/en-us/linkedin/shared/references/v2/profile/profile-picture
Upvotes: 2