【发布时间】:2020-12-09 23:59:21
【问题描述】:
尝试从 Instagram 获取访问令牌
$params = array(
'app_id' => $this->clientId,
'app_secret' => $this->clientSecret,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUrl,
'code' => $this->request->code
);
$ch = curl_init();
$endpoint = $this->getBaseUrl() . 'oauth/access_token';
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
curl_close($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
dd($response,$header_size,$header,$body);
$response = json_decode($response, true);
return $response;
这个带有 CURL 的代码工作正常。
Request Data Laravel 文档。
$response = Http::post($this->getBaseUrl() . 'oauth/access_token', [
'app_id' => $this->clientId,
'app_secret' => $this->clientSecret,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUrl,
'code' => $this->request->code
]
);
return $response->body();
但不能使用 Laravel Http Client.it return Client Id is missing但我作为参数发送。
【问题讨论】:
-
有点不清楚您要达到的目标。似乎您几乎每个点都在尝试访问自己的 OAuth,对吗?无论如何,您不应该发送
client_id而不是app_id,如下所述:laravel.com/docs/8.x/passport#requesting-tokens -
请求的内容类型是什么
-
@MaartenVeerman 从 Instagram 获取访问令牌。