Parse's REST API and PHP Curl requests - how to Parse's REST API and PHP Curl requests - how to curl curl

Parse's REST API and PHP Curl requests - how to


Put it into headers

$headers = array(    "X-Parse-Application-Id: $MyApplicationId",    "X-Parse-REST-API-Key: $MyParseRestAPIkey");$handle = curl_init(); curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);


 <?php   $url = 'https://api.parse.com/1/classes/GameScore';   $appId = 'YOUR_APP_ID';   $restKey = 'YOUR_REST_KEY';   $headers = array(     "Content-Type: application/json",     "X-Parse-Application-Id: " . $appId,     "X-Parse-REST-API-Key: " . $restKey   );   $objectData = '{"name":"Adarsh", "age":"26"}';   $rest = curl_init();   curl_setopt($rest,CURLOPT_URL,$url);   curl_setopt($rest,CURLOPT_POST,1);   curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);   curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);   curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);   curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);   $response = curl_exec($rest);   echo $response;   print_r($response);   curl_close($rest);   ?>  


use this function for all object insert ,the object that should be created as associative array with correct index

 function insertObject($classname,$object){ $ appId="xxxxx";   $restKey="xxxx"     $url = 'https://api.parse.com/1/classes/'.$classname;    $rest = curl_init();        curl_setopt($rest, CURLOPT_RETURNTRANSFER, 1);        curl_setopt($rest, CURLOPT_FRESH_CONNECT, FALSE);//use cache if available        curl_setopt($rest, CURLOPT_TIMEOUT, 10); //10 sec timeout        curl_setopt($rest,CURLOPT_URL,$url);        curl_setopt($rest,CURLOPT_PORT,443);        curl_setopt($rest,CURLOPT_POST,1);        curl_setopt($rest,CURLOPT_POSTFIELDS,  json_encode($object));        curl_setopt($rest,CURLOPT_HTTPHEADER,            array("X-Parse-Application-Id: " . $appId,                "X-Parse-REST-API-Key: " . $restKey,                "Content-Type: application/json"));        curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, false);//to avoid certificate error        $response = curl_exec($rest);        echo $response ;}