<?php
define('OAUTH_TOKEN_URL','https://api.example.com/oauth/token');
$url ='' ;
$client_id = '';
$client_secret = ''; /your client secret from api
$data = "grant_type=authorization_code&code=".$_GET['code']."&client_id=".$client_id."&client_secret=".$client_secret."&redirect_uri=".$url;
$headers = array(
'Content-Type:application/x-www-form-urlencoded',
);
$response = curlPost($data,$headers);
print_r($response);
function curlPost($data,$headers){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,OAUTH_TOKEN_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
return $server_output;
curl_close ($ch);
}