PHP cURL

Below is a simple cURL example that may be used in place of Zend_Http_Client. The resulting response will still need to be parsed and handled appropriately. Additional cURL options may be used and the Content-Length Header will need to be adjusted when making POST and PUT requests to the API.

Get Authorisation Code
<?php
 
// This example is specifically for the "tokenAuthorizationCode" method above
 
$request = curl_init($url);
curl_setopt($request, CURLOPT_USERPWD, $config['client_id'] . ":" . $config['client_secret']);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Content-Length: 0'));
curl_setopt($request, CURLOPT_HEADER, 1);
curl_setopt($request, CURLOPT_POST, 1);
curl_setopt($request, CURLOPT_TIMEOUT, 10);
curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);
 
if (isset($config['cookies'])) {
    $cookieString = array();
    foreach ($config['cookies'] as $name => $value) {
        $cookieString[] = $name . '=' . $value;
    }
    curl_setopt($request, CURLOPT_COOKIE, implode(';', $cookieString));
}
 
$result = curl_exec($request);
curl_close($request);
 
// Parse $result HEADER to determine if the request is successful and json_decode() the $result BODY for content

Related pages