1

I am using PHP's build in cURL library to make GET requests to the Meetup API. This is an example of a query I'm running to view every meetup group 25 miles from central park:

https://api.meetup.com/groups.json/?lat=40.75&lon=-73.98999786376953&order=members&page=200&offset=0&key=MY_API_KEY

This query works correctly when passed to the browser, it returns the excepted 200 largest groups.

When I run this in a PHP script I'm using cURL set with these options

curl_setopt($cURL, CURLOPT_URL, $groups_url);
curl_setopt($cURL, CURLOPT_HEADER, 1);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);

$json_string = curl_exec($cURL);

I am hoping to be able to get the cURL to execute and return a json string that I can parse, but for some reason I do not understand, the result of curl_exec is always NULL, I am not sure why an input that works in the browser will not work in a script, this could just be me being dumb. Thank you for your help in advance.

whoan
  • 8,143
  • 4
  • 39
  • 48
usumoio
  • 3,500
  • 6
  • 31
  • 57
  • "Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure." Are you sure it is returning a NULL? – Bryan Wolfford Aug 20 '12 at 21:50

1 Answers1

3

this is becuase its https [SSL]. so the quick fix is to add this line

curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0);

here example of it all working

$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, "https://api.meetup.com/groups.json/?lat=40.75&lon=-73.98999786376953&order=members&page=200&offset=0&key=MY_API_KEY");
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0);
$json_string = curl_exec($cURL);
echo $json_string;
user1558223
  • 197
  • 1
  • 9
  • That fixed it perfectly. Thank you. It turned out every other setting was right. This fix addressed the last issue and a proper JSON object was returned. – usumoio Aug 20 '12 at 23:51