Php: Get URL content (json) using cURL

I want to access https://graph.facebook.com/19165649929?fields=name (obviously it is also available with "http") using cURL to get the contents of the file, more specific: I need a "name" (this is json ) Since allow_url_fopen is disabled on my web server, I cannot use get_file_contents! So I tried it like this:

<?php
$page = 'http://graph.facebook.com/19165649929?fields=name';
$ch = curl_init();
//$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
//curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>

With this code, I get a blank page! When I use another page, for example http://www.google.com , it works like a charm (I get the contents of the page). I think facebook is checking what I don't know ... What could it be? How can I make the code work? Thank!

+3
source share
2 answers

Have you posted it here twice? php: Get html source code with cURL

however, in the thread above, we found that your problem is unable to resolve the host, and this was the solution:

//$url = "https://graph.facebook.com/19165649929?fields=name";
$url = "https://66.220.146.224/19165649929?fields=name";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: graph.facebook.com'));
$output = curl_exec($ch);
curl_close($ch); 
+6
source

Please note that the Facebook Graph API requires authentication before you can view any of these pages.

You basically have two options. Either you log in as an application (you registered earlier), or as a user. See the api documentation for how it works.

- PHP-SDK. . cURL . , , .

.

0

Source: https://habr.com/ru/post/1762098/


All Articles