-3

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.

ryo
  • 2,009
  • 5
  • 24
  • 44
  • adding 'curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);' seems to help. Also, decode the result '$res' as a separate step. This allows you to read the response. – Ryan Vincent Jul 13 '14 at 08:52

1 Answers1

0

open php.ini file at wamp/bin/php/php5.4/php.ini \

on XAMP there are three php.ini

C:\Program Files\xampp\apache\bin\php.ini
C:\Program Files\xampp\php\php.ini
C:\Program Files\xampp\php\php4\php.ini

enter link description here

search ;extension=php_curl.dll and remove semicolon

extension=php_curl.dll then save and and restart server

and change the port of server from 80 to 88 , 8088 ..etc etc, and how to change the port you can see here

Community
  • 1
  • 1
Muhammad Ali
  • 1,992
  • 1
  • 13
  • 20
  • Thank you for your response. I've already removed it. My php.ini is in C:\xampp\php. I don't where wamp/bin/php/php5.4/php.ini is. – ryo Jul 13 '14 at 06:06
  • Ok now you can see xamp icon is green at your taskbar , right click on it restart the server and goto php extension see is php curl on or not or open phpinfo(); – Muhammad Ali Jul 13 '14 at 06:16
  • I don't know where xampp icon is and where my taskbar is. But phpinfo() shows [[ curl cURL support enabled cURL Information 7.24.0 Age 3]] Has curl been available? – ryo Jul 13 '14 at 06:24
  • Now you need to change the port of Apache it will be 80 , you have to change it port http://veerasundar.com/blog/2009/07/how-to-change-xampp-server-port/ or http://stackoverflow.com/questions/11294812/how-to-change-xampp-apache-server-port – Muhammad Ali Jul 13 '14 at 06:34