Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenGraph with PHP (cUrl requests for actions)

I created an app for my website, set action (read) and object (article), and placed the objects code (META tags in the head) at the article page on my website.

Now, I want to know how to send a cUrl request whenever a user reads an article on my website, so it'll feature on his wall.

When I press the "get code" link near the action, that's what I get:

curl -F 'access_token=***' \
 -F 'article=http://example.com' \
    'https://graph.facebook.com/me/yellowheart:read'

(There's an actual access token of course).

Now, how do I make it happen?

Daniel.

like image 519
Naxon Avatar asked Oct 07 '11 11:10

Naxon


2 Answers

Using the PHP SDK you would use the api method.

$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';

$facebook = new Facebook($config);
...
$facebook->api('https://graph.facebook.com/me/yellowheart:read?  
                article=http://example.com'','POST');

You could also do a raw request

$myurl = 'https://graph.facebook.com/me/yellowheart:read? 
          article=http://example.com&access_token=ACCESS_TOKEN&method=post';

$result = file_get_contents($myurl);
like image 121
brian_d Avatar answered Nov 15 '22 20:11

brian_d


$facebook->api('/me/'.FB_NAME_SPACE.':action','POST',
   array('facility'=>'http://www.mysite.com/object?id=1')
                             );

https://developers.facebook.com/docs/reference/php/facebook-api/

like image 31
Cullen SUN Avatar answered Nov 15 '22 21:11

Cullen SUN