I'm making an application, using Google URL Shortener API.
On MackBook Pro, the following code does work, but on Windows PC, it doesn't work and shows only "NULL" on the screen.
<?php
// APIkey
$apiKey = '[Here is my API KEY]';
$longUrl = "http://www.absolute-keitarou.net/blog/";
$url1 = 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey;
$params = json_encode(array(
"longUrl" => $longUrl
));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = json_decode(curl_exec($curl));
curl_close($curl);
var_dump($res);
?>
On the MacBook, the code does work properly and shows the following.
object(stdClass)#1 (3) { ["kind"]=> string(16) "urlshortener#url" ["id"]=> string(19) "http://goo.gl/TMII0" ["longUrl"]=> string(38) "http://www.absolute-keitarou.net/blog/" }
I want the Windows PC to shows the same output as the MacBook. Please tell me what I should do.