Curl set returns resource id 34

1.2k views Asked by At

I was using the code below for the past week without any issues. But recently, client changed the server settings and I had this weird issue. My curl request now returns id as 35 and will not generate auth token. I checked php_info function and found that curl is already enabled on the server. I know the code here is perfect since it was working perfectly before and in another server too. Does anyone know what should I look for in server -Cpanel, or is there any changes needed to the code?

function fetchUrl($url)
{ 
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  // You may need to add the line below
  // curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  $feedData = curl_exec($ch);
  curl_close($ch); 
  return $feedData;
}

$profile_id = "XXXXXXXXXXXXX";

//App Info, needed for Auth
$app_id = "XXXXXXXXXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXXXXXXXXXXX";
//Retrieve auth token
$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$app_id}&client_secret={$app_secret}");
$json_object = json_decode(fetchUrl("https://graph.facebook.com/{$profile_id}/feed?{$authToken}"));
1

There are 1 answers

0
Elyor On

set the curl SSL version to version 3

curl_setopt($ch, CURLOPT_SSLVERSION,3);

this should work