Kri*_*ish 19 javascript facebook callback facebook-like facebook-javascript-sdk
我有一个网页,我在其中放置了一个类似于Facebook的共享按钮,并且还存在相应的javascript回调函数.
现在问题是,javascript回调仅在用户"喜欢"时触发,并且在按下"共享"按钮时似乎不会触发.
就像我需要在每次他/她共享链接时奖励用户.而对于"喜欢",用户只能喜欢链接一次(不考虑不喜欢/重新喜欢).
我知道不推荐使用"共享"按钮.但Facebook现在提供了一个带有类似按钮的分享按钮.资料来源:https://developers.facebook.com/docs/plugins/like-button/
有没有办法从这个共享按钮触发这个回调方法?
这是我的代码:
我的HTML中BODY标记开头的代码: -
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: ' My App ID ',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('edge.create', function(response) {
alert('You liked the URL: ' + response);
});
};
(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>
Run Code Online (Sandbox Code Playgroud)
用于显示Like&Share按钮的代码: -
<div class="fb-like" data-href=" My URL " data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>
Run Code Online (Sandbox Code Playgroud)
Sah*_*tal 29
您无法使用此按钮获取共享回调.您可以改为创建自己的分享按钮,并 在其点击时调用Feed对话框 -
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
Run Code Online (Sandbox Code Playgroud)
完整代码在这里
$("#bodyarea").on('click', '.share_fb', function(event) {
event.preventDefault();
var that = $(this);
var post = that.parents('article.post-area');
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/en_US/sdk.js', function(){
FB.init({
appId: '822306031169238', //replace with your app ID
version: 'v2.3'
});
FB.ui({
method: 'share',
title: 'TTitle Test',
description: 'Test Description Goes here. Tahir Sada ',
href: 'https://developers.facebook.com/docs/',
},
function(response) {
if (response && !response.error_code) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
将您的应用程序ID更改为工作
归档时间: |
|
查看次数: |
35476 次 |
最近记录: |