Integrating trustpilot unique link feature for customer with php and curl

My need is to generate unique link for the customers of Trustpilot widget.For that, I need to have an access token.I tried all possible ways but facing same error

{“reason”:“Unknown grant_type”} "

Below is my code for the same

$data = array(
GRANT_TYPE => GRANT_TYPE_VALUE,
TRUSTPILOT_USERNAME => TRUSTPILOT_USERNAME_VALUE,
TRUSTPILOT_PASSWORD => TRUSTPILOT_PASSWORD_VALUE,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,“https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Authorization: Basic base64 encoded apikey:secretkey’,
‘Content-Type: application/json’
));
$server_output = curl_exec($ch);
curl_close($ch);
var_dump($server_output);

Thanks in Advance

1 answer

  • answered 2017-10-11 20:39 Bardur Pihl

    Have you tried setting Content-Type to application/x-www-form-urlencoded?