简体   繁体   English

使用OpenGraph和PHP(cUrl请求操作)

[英]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. 我为我的网站创建了一个应用程序,设置了动作(阅读)和对象(文章),并在我网站的文章页面上放置了对象代码(头部的META标签)。

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. 现在,我想知道当用户在我的网站上阅读文章时如何发送cUrl请求,因此它将在他的墙上发布。

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. 丹尼尔。

Using the PHP SDK you would use the api method. 使用PHP SDK,您将使用api方法。

$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);
$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/ https://developers.facebook.com/docs/reference/php/facebook-api/

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. 希望在某种程度上有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM