How can cURL be used to access Facebook Graph API in PHP?

To access Facebook Graph API in PHP using cURL, you can make a GET request to the API endpoint with the necessary access token. This will allow you to retrieve data from Facebook such as user information, posts, and more.

<?php

$access_token = 'YOUR_ACCESS_TOKEN';
$graph_url = 'https://graph.facebook.com/me';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $graph_url . '?access_token=' . $access_token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

if(curl_errno($ch)){
    echo 'Error: ' . curl_error($ch);
}

curl_close($ch);

$data = json_decode($response, true);

print_r($data);

?>