I'm struggling a bit to exchange my verification code for an access token in XERO. It should be a straightforward operation so I'm trying to avoid the overhead of using libraries. Here's the code so far (Assume any variables have already been defined before we get to here)
// set up the concatenated string
$string = urlencode('grant_type=authorization_code&code='.$code.'&redirect_uri='.$redirecturi);
// set up the header array
$headerarray = array('authorization:Basic '.base64_encode($clientid.":".$secret), 'Content-Type: application/x-www-form-urlencoded');
// first attempt with curl
curl_setopt($ch, CURLOPT_URL, 'https://identity.xero.com/connect/token');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerarray);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
echo curl_exec($ch);
// second attempt with http post
$options = array(
'http' => array(
'header' => $headerarray,
'method' => 'POST',
'content' => $string
)
);
$context = stream_context_create($options);
echo file_get_contents('https://identity.xero.com/connect/token', false, $context);
In neither case am I getting any response back. Many thanks in advance for any help!