Greg
Greg

Reputation: 21

Using PHP to Add Facebook Open Graph Read Action

I'm trying to get Facebook to publish a read action using PHP. I've coded it totally wrong and need a little help:

<?php    
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>

<?php

curl -F 'access_token=MY ACCESS TOKEN' \
     -F 'article=echo 'echo curPageURL();' \
        'https://graph.facebook.com/me/news.reads'

?>

The second part is that bit I can't translate into PHP properly. I've no idea where to start as I'm a novice with PHP and only just learning the Open Graph API.

Upvotes: 0

Views: 643

Answers (2)

FluffyKitten
FluffyKitten

Reputation: 14312

I suggest you used the Facebook PHP SDK https://developers.facebook.com/docs/reference/php/, it was developed by Facebook to provide access to their API and it manages the cURL connection for you.

Upvotes: 1

tcole
tcole

Reputation: 927

Take a look at the cURL functions in PHP.

https://www.php.net/manual/en/ref.curl.php

That should help.

Upvotes: 1

Related Questions