调用 /v2/me 时出现'Resource me does not exist' API 错误



当我尝试调用URL GET:/v2/me时,我收到错误"资源我不存在"。

获取:https://api.linkedin.com/v2/me?projection=(id,名字,姓氏,个人资料图片)

令牌接收自:https://www.linkedin.com/oauth/v2/accessToken

授权网址:

$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';

请求:

...
$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();

响应:

{#81 ▼
+"serviceErrorCode": 0
+"message": "Resource me does not exist"
+"status": 404
}

该接口的功能:

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;
}

迟到的回应,

在使用 python 和 python 的请求包时对 LinkedIn 进行 API 调用时,我遇到了类似的问题。 就我而言,我通过使用GET请求解决了这个问题。我一直在尝试使用POST请求类型进行 API 调用,这使得资源不存在。

这是文档的链接,他们给出了URL应该是什么样子的示例: https://learn.microsoft.com/en-us/linkedin/shared/references/v2/profile/profile-picture

最新更新