Josh Oldham Josh Oldham - 1 year ago 206
PHP Question

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

I am using the excellent Parse as a data store, but need to access it through PHP (as a perhaps irrelevant bit of detail - I am having to access it through PHP in order for Facebook scrapers to recognise dynaically generated tags on my page).

Parse have a Rest API, and basic instructions on how to use them. For example, to retrieve an object:

curl -X GET \

-H "X-Parse-Application-Id: [My application ID]" \

-H "X-Parse-REST-API-Key: [My Parse Rest API key]" \

Unfortunately, I have no idea how to integrate this with PHP Curl examples I've seen online. I gather:

curl_setopt($ch, CURLOPT_USERPWD,

..might be involved. As might:

curl_setopt($ch, CURLOPT_URL, $Url);

but I could be way off. I am really sorry to not be able to figure this out myself - but I think this is still a valid question as it is very confusing to those who haven't used Curl/PHP before. Basically - I'm looking for information as basic as where to put the quoted example from the Parse docs...

Thanks in advance


Hey all, here is the solution as I configured it. Thanks to debianek for getting me going in the right direction.

if ($_GET['id']) {
$imageId = $_GET['id'];
MyApplicationId = '[ID]';
$MyParseRestAPIKey = '[API Key]';
$url = ''.$imageId;

$headers = array(
"Content-Type: application/json",
"X-Parse-Application-Id: " . $MyApplicationId,
"X-Parse-REST-API-Key: " . $MyParseRestAPIKey

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($handle);

$array = json_decode($data);

$title = $array->title;

..and so on. Hope that helps.

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download