There was a script on the server that worked with api facebook for a year.

$json_object = file_get_contents('https://graph.facebook.com/' . $page_id . '/feed?fields=permalink_url&limit=5&access_token=' . $access_token); 

Now the hoster has pissed off something and everything flew (on LAN everything continues to work), requests do not reach Facebook. I understand they changed the parameter allow_url_fopen . How to rewrite this query under cUrl? or somehow solve the problem that would work? Now he writes:

 Warning: file_get_contents(***): failed to open stream: Π’ соСдинСнии ΠΎΡ‚ΠΊΠ°Π·Π°Π½ΠΎ in ***.php on line 18 Notice: Trying to get property of non-object in ***.php on line 26 Warning: Invalid argument supplied for foreach() in ***.php on line 28 

Rewritten under curl:

 // 1. инициализация $ch = curl_init(); // 2. ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ url curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/****/feed?fields=permalink_url&limit=5&access_token=****"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); // 3. ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ HTML Π² качСствС Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π° $output = curl_exec($ch); echo $output; if ($output === FALSE) { //Π’ΡƒΡ‚-Ρ‚ΠΎ ΠΌΡ‹ ΠΎ Π½Π΅ΠΉ ΠΈ скаТСм echo "cURL Error: " . curl_error($ch); return; } // 4. Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ соСдинСниС curl_close($ch); 

Received:

 cURL Error: couldn't connect to host 

Maybe the https problem?

  • try CURLOPT_SSL_VERIFYPEER false, CURLOPT_SSL_VERIFYHOST false - Jean-Claude
  • added these options, cURL Error anyway: couldn't connect to host - nueq

0