This is the code I use to make that post request using curl in php:
function post_helper($url, $data)
{
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//set encoding
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$retval = curl_exec($ch);
return json_decode($retval);
}
$data = "grant_type=authorization_code" .
"&client_id=${api_key}" .
"&redirect_uri=${redirect_url}" .
"&code=${code}" .
"&code_verifier=${code_verifier}";
$response = post_helper('
https://api.etsy.com/v3/public/oauth/token', $data);
if $response->error is set, then something went wrong and it will usually provide a descriptive error message. If the request is successful, you can get the access token from $response->access_token.