Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当用户共享到facebook的链接时更新数据库_Php_Facebook_Facebook Graph Api - Fatal编程技术网

Php 当用户共享到facebook的链接时更新数据库

Php 当用户共享到facebook的链接时更新数据库,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,一旦用户在我的网站上共享了链接,是否可以更新数据库 例如,如果他们共享链接,一些积分将被授予他们的帐户 我怎样才能确保他们真的共享facebook的链接,而不是仅仅单击共享然后关闭弹出窗口 我对facebook不太熟悉,刚试过谷歌,但还是没有找到答案 多谢各位 编辑: 您不需要facebook,只要有人单击页面上的Like按钮,您就可以执行Javascript AJAX调用。调用会写入数据库。只需将单击事件保存到按钮。是的,这是可能的 示例链接: 散文示例代码 if(isset($_GET['

一旦用户在我的网站上共享了链接,是否可以更新数据库

例如,如果他们共享链接,一些积分将被授予他们的帐户

我怎样才能确保他们真的共享facebook的链接,而不是仅仅单击共享然后关闭弹出窗口

我对facebook不太熟悉,刚试过谷歌,但还是没有找到答案

多谢各位

编辑:


您不需要facebook,只要有人单击页面上的Like按钮,您就可以执行Javascript AJAX调用。调用会写入数据库。只需将单击事件保存到按钮。

是的,这是可能的

示例链接:

散文示例代码

if(isset($_GET['share']))
{
    if(mysql_query("insert into table X() value()"))
    {
        //open window, you can use header('location:..') or meta redirect or another way, in this sample i'm using javascript window.open;
        echo '<script>window.open("http://www.facebook.com/sharer.php?u='.urlencode($_GET['share']).'","share","width=600,height=400");</script>';
    }
}
if(isset($\u GET['share']))
{
if(mysql_查询(“插入表X()值()”)
{
//打开窗口,您可以使用header('location:..)或元重定向或其他方式,在这个示例中,我使用的是javascript window.open;
“回声”窗口。打开(“http://www.facebook.com/sharer.php?u=“.urlencode($_GET['share'])”,“share”,“width=600,height=400”);
}
}

要实现facebook的“喜欢”按钮,也许可以帮助您

我想您正在寻找这个 您需要订阅此活动。

更新(2013年8月21日):自最初发布此活动以来,Facebook的api已更改。追踪喜欢的人的方式仍然是一样的(阅读下面的原始答案),但是共享按钮的状态已经改变

弃用消息/信息。不再在文档中的任何位置可见,但可以在中看到。共享按钮似乎仍然可用。但facebook并没有直接的方式来追踪一个共享。我也不知道有任何追踪股票的黑客


原始答案:

来自Facebook文档,网址为

“共享”按钮已被弃用,取而代之的是“相似”按钮,将不再受支持。 请尽可能使用Like按钮,以最大限度地提高应用程序的流量

因此,我将告诉您如何使用like按钮:

首先使用

window.fbAsyninit=函数(){
FB.init({
appId:'你的应用程序ID',//应用程序ID
channelUrl:'//WWW.YOUR_DOMAIN.COM/channel.html',//频道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
//这里有额外的初始化代码
//你可以在这里订阅活动
//仅当用户喜欢时才会触发edge.create事件(这意味着在单击“喜欢”按钮时,墙柱已经发生)
FB.Event.subscribe('edge.create',
功能(响应){
警报(“您喜欢URL:”+响应);
//您可以对后端进行一些ajax调用并更新数据库
}
); 
};
//异步加载SDK
(职能(d){
var js,id='facebook jssdk';if(d.getElementById(id)){return;}
js=d.createElement('script');js.id=id;js.async=true;
js.src=“//connect.facebook.net/en_US/all.js”;
d、 getElementsByTagName('head')[0].appendChild(js);
}(文件);
在页面的某个地方包括like按钮


您还可以更改“喜欢”按钮中显示的单词,从“喜欢”改为“推荐”,您应该尝试从中自动生成“喜欢”按钮代码。

谢谢您的回复。共享如何?我想知道他们是否只是单击“共享”按钮,但没有完全共享它(只需关闭弹出的共享窗口)…在这种情况下,您将需要一些链接共享平台的API,因为从技术上讲,用户将离开您的站点。嗯…我该怎么做?有什么例子吗?谢谢你的回答,我仍然在寻找一种方法来处理用户是否真的共享链接。但是如果用户不共享链接怎么办?db条目将无效。您能告诉我您正在使用哪些插件来共享吗?我的意思是像还有什么?您是否也在使用
feed
post?@bool.dev感谢您的回复。很抱歉,我不太明白,但我只是在使用facebook开发者在我的php脚本中提供的共享按钮代码。@bool.dev谢谢。我对代码提出了质疑。太好了,这是旧的共享按钮,已被like按钮取代,如果可能的话,我还是会想办法。@bool.dev我明白了,非常感谢,我也会检查一下。非常感谢您的解释和链接,我现在就试试。再次感谢您的患者。祝您度过愉快的一天。很高兴我能帮上忙,在正确、完整地实现javascript sdk之前,您必须弄清楚javascript sdk的一些方面,因此也请阅读更多关于javascript sdk的内容。
if(isset($_GET['share']))
{
    if(mysql_query("insert into table X() value()"))
    {
        //open window, you can use header('location:..') or meta redirect or another way, in this sample i'm using javascript window.open;
        echo '<script>window.open("http://www.facebook.com/sharer.php?u='.urlencode($_GET['share']).'","share","width=600,height=400");</script>';
    }
}
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
    // you can subscribe to events here
    // edge.create event is fired only when the user likes (which means that the wall post has already happened, when the like button was clicked) 
    FB.Event.subscribe('edge.create',
   function(response) {
    alert('You liked the URL: ' + response);
            // you can do some ajax call to your backend and update your database
   }
); 
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
  </script>
<fb:like href="http://example.com/fblike/" 
     send="true" width="450" show_faces="false"
     >
</fb:like>