Using OpenGraph with PHP (cUrl requests for actions)

点点圈 提交于 2019-12-21 00:54:19

问题


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.


回答1:


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);



回答2:


$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/




回答3:


I followed the tutorial "Recipe Box" and found out how to "make it happen" in there step by step. Hope that helps in some way.



来源:https://stackoverflow.com/questions/7686422/using-opengraph-with-php-curl-requests-for-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!