且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在自己的网站上提交之前检查是否有人喜欢页面

更新时间:2023-12-01 20:53:58

您可以使用 Javascript SDK 检查是否有人点击了赞"按钮

You can check if someone clicks the like button using the Javascript SDK

您可以使用社交插件或 XFBML 按钮,实现 XFBML 按钮和 Javascript SDK,您可以在这里找到:https://developers.facebook.com/docs/reference/javascript/>

然后你可以创建一个事件监听器来监听用户是否点击了喜欢按钮:

You can either use the social plugin or the XFBML button, Implementing the XFBML button and the Javascript SDK you can find here: https://developers.facebook.com/docs/reference/javascript/

Then you can create an event listener that listens if an user clicks the like button:

https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

使用此功能,您可以存储有人点击了赞"按钮,然后将其保存到您的数据库或会话中,让用户下载他们的曲目.

https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

你的代码应该是这样的

Your code would be something like this

<脚本>window.fbAsyncInit = function() {FB.init({appId : 'YOUR_APP_ID',//应用 IDchannelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html',//频道文件status : true,//检查登录状态cookie : true,//启用 cookie 以允许服务器访问会话xfbml : true//解析 XFBML});FB.Event.subscribe('edge.create',功能(响应){alert('你喜欢的网址:' + response);});};//异步加载SDK(功能(d){var js, id = 'facebook-jssdk';if (d.getElementById(id)) {return;}js = d.createElement('脚本');js.id = id;js.async = true;js.src = "//connect.facebook.net/en_US/all.js";d.getElementsByTagName('head')[0].appendChild(js);}(文档));

<div id="fb-root"></div> <div class="fb-like" data-href="http://www.***.com" data-send="false" data-width="450" data-show-faces="true"></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 }); FB.Event.subscribe('edge.create', function(response) { alert('You liked the URL: ' + response); } ); }; // 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));