Question:

I have been seeing document and samples on accessing the Graph API via CURL. But how can I use cURL in my PHP Scripts?

 

 

 

Answer:

Appreciate if you can like this page if you find it useful! - Click "Like"

As an example, if you want to post to your feed by using cURL, it would be something like:

curl -F 'access_token=...' \
     -F 'message=I am posting to my own feed. I am awesome.' \
     https://graph.facebook.com/me/feed  

The corresponding PHP code would be:

$args = array('access_token' => $myToken,
              'message' => 'testing message'
              );
$ch = curl_init(); 
$url = 'https://graph.facebook.com/me/feed'; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $args); 
$data = curl_exec($ch); 
curl_close($ch);

For more details on how to use CURL in PHP, please refer to php.net.

 

 

Find my FAQ on Facebook Development useful? Download the PDF for all the FAQs HERE!