I am currently trying to use the Nest API but I can't get past the authorization part. Here is the PHP code I use to call the API :
//access token url used for authorization
$url="https://api.home.nest.com/oauth2/access_token?code=".$_GET['pin']."&client_id=".$api_key."&client_secret=".$secret_key."&grant_type=authorization_code";
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
//https
curl_setopt($ch, CURLOPT_SSLVERSION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST,true);
//to have headers in response
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec ($ch);
if($result){
echo "Result : " .$result;
}else{
echo curl_error($ch);
}
And I get the following result for this call :
Result : HTTP/1.1 200 Connection established HTTP/1.1 400 BAD_REQUEST Content-Length: 0 Connection: Close
Is there other options I need to set in order to get it working?
EDIT : The generated url ($url) works fine with HTTPRequester (Firefox addon) so the problem comes most certainly from the curl request itself
Thanks in advance.