I'm using Google Url Shortener service in a PHP code.
It's working but I'd like to improve performances and I've seen that the documentation (rif. https://developers.google.com/url-shortener/v1/performance) suggests working with partial resources and using gzip.
I've adopted the partial resources approach and works fine but now I'd like to use the gzip suggestion too.
By now my code is
function CompactUrl($longUrl)
{
$apiKey = API;
$postData = array('longUrl' => $longUrl);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey'&fields=id);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
//print 'Response = '.$response;
// Change the response json string to object
$json = json_decode($response);
curl_close($curlObj);
$shortLink = get_object_vars($json);
return $shortLink['id'];
}
The Google documentation says to use
Accept-Encoding: gzip
User-Agent: my program (gzip)
My problem is that I don't know how to convert this in my PHP code ......
Any suggestions?
Thank you very much in advance!!!
Cesare