send email after facebook comment is posted - facebook

I have this code:
$output = '<div id="fb-root"></div>
<script> window.fbAsyncInit = function() {
FB.init({
appId : "xxx",
status : true,
cookie : true,
oauth : true,
xfbml : true
});
$(window).load(function(){
FB.Event.subscribe("comment.create", function(response) {
var data = {
action: "fb_comment",
url: "xxx.com"
};
$.post( "mail.php", data );`
});
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "facebook-jssdk"));</script>
<div class="fb-comments" data-href="'. $url .'" data-num-posts="'. $amount .'" data-notify="true" data-width="'. $width .'" data-colorscheme="'.$style.'"></div>';
And then the send email code in the mail.php file. (This code works)
I think the issue is the FB.Event.subscribe code, I can't figure out how to call the mail.php file to send the email only when a comment is posted.
I have placed the code in the facebook_comments_module file of the facebook_comments module from drupal. (my site is a drupal site)

This worked:
`$output = '<div id="fb-root"></div>
<script> window.fbAsyncInit = function() {
FB.init({
appId : "xxx",
status : true,
cookie : true,
oauth : true,
xfbml : true
});
/* All the events registered */
FB.Event.subscribe("comment.create", function(response) {
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","../xxx/mail.php?response1="+ response.href,true);
xmlhttp.send();
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "facebook-jssdk"));</script>
<div class="fb-comments" data-href="'. $url .'" data-num-posts="'. $amount .'" data- notify="true" data-width="'. $width .'" data-colorscheme="'.$style.'"></div>';`

Related

Facebook SDK login error "This page isn't available"

I'm having a problem with Facebook SDK, when I log in I get the error "This page isn't available", but sometimes I log in successfully. I have searched for answers in many communities but still no results, please help me
// Button
<div class="fb-login-button" data-size="large" data-button-type="login_with" data-auto-logout-link="false" data-use-continue-as="true" scope="public_profile,publish_video,user_videos" onlogin="checkLoginState()">Login Facebook</div>
//JS
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
FB.init({
appId : xxx,
cookie : true,
xfbml : true,
version : 'v3.3'
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
function statusChangeCallback(response) {
if (response.status === 'connected') {
console.log('logined!');
} else {
console.log('not login!');
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
Screenshot:

facebook comments not show

I added Facebook Comment on my site.
window.fbAsyncInit = function() {
FB.init({
appId : appId,
xfbml : true,
version : 'v2.5'
});
FB.Event.subscribe('comment.create', addedComment);
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/ru_RU/sdk.js#xfbml=1&version=v2.5appId=appId;
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
appId - number my application on facebook.
On page add next code:
echo "\n<div class=\"fb-comments\" data-href=".the_permalink()." data-num-posts=\"7\" data-width=\"470\"></div>";
(I using Wordpress) Commentbox show on site, comments show in moderation tools, but on refresh page commentbox is empty.Why?
(sorry for my English)

How to check if user has shared website on Facebook

This is what I did but nothing happens when the I click on the share on facebook link:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Sample Facebook share</title>
</head>
<body>
<script src="http://connect.facebook.net/en_US/sdk.js" type="text/javascript" charset="utf-8"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '1407416289470597',
xfbml : true,
version : 'v2.0'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function test()
{
FB.ui(
{
method: 'share',
href: 'https://www.mywebsite.com',
},
function(response) {
if (response && !response.error_code) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
}
);
}
</script>
Share
</body>
</html>
Any ideas? Nothing happens when I click on the Share link.
I don't know what's wrong. I copy-pasted this example as well, still nothing.
Tested it on a VPS with SSL and on a shared server as well.
The Feed Dialog is deprecated, as shown here: https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.0
You're better off with implementing the new Share Dialog. You can find the guide here: https://developers.facebook.com/docs/sharing/reference/share-dialog
The SDK initialization also should call the new sdk.js file:
window.fbAsyncInit = function() {
FB.init({
appId : '{your-app-id}',
xfbml : true,
version : 'v2.0'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Create a custom Facebook Share link

So this question has been asked before, but no one wants to do it in the manner that I want to, so bear with me while I try and explain. The FB.ui API has some functions that I find useful, mainly that I can dynamically change the description. So, I want to put the FB.ui into a link that a user can click and then a pop up will appear where they can share my webpage. So far what I have is:
<div id="fb-root"></div>
<script>
function shareFB(){
window.fbAsyncInit = function() {
FB.init({
appId : '42352352356463',
status : true,
xfbml : true
});
FB.ui(
{
method: 'feed',
name: 'name',
caption: 'caption',
description: (
a
),
link: 'http://www.image.com/',
picture: 'http://www.image.com/static/3.png'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
</script>
and then I have a link to this here:
<a class="links" onclick='shareFB()' href="#"> Share! </a>
But this doesn't work. Why not!
You are loading the facebook SDK when you click the button and that's the wrong way to load it, change your script to this:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '42352352356463', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/pt_PT/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function shareFB(){
var obj = {
method: 'feed',
name: 'name',
caption: 'caption',
description: 'description',
link: 'http://www.image.com/',
picture: 'http://www.image.com/static/3.png'
};
function share(response){
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
FB.ui(obj, share);
};
</script>

open graph and tpl file

i want to integrate open graph using sdk and facebook login button (token action)
the probleme is with the smarty template tpl file
in fact i tested all my code on simple html file, and it work like a charme : http://zdig1.biz/1.htm
the same code when i report it to tpl file don't work
of corse by adding {literal}
you can compare the other link with this
http://zdig1.biz/video/naruto-shippuden/317-video_7605be4c2.html
the facebook boutton called time line dont exit
and the publich one dont work
<div id="fb-root"></div>
{literal}<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '48439698629',
channelUrl : '//zdig1.biz/channel.html',
status : true,
cookie : true,
xfbml : true
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>{/literal}
{literal}<script type="text/javascript">
function postArticle()
{
FB.api(
'me/video.watches',
'post',
{
video: "http://zdig1.biz/video/naruto-shippuuden/321-video_f69d2a355.html"
},
function(response) {
if (!response || response.error) {
alert('Post was not published.');
} else {
alert('Post was published. Action ID: ' + response.id);
}
});
}
</script>{/literal}
and the action one
<fb:login-button onlogin = 'postArticle()' perms="email,publish_actions,user_actions.video">
Timeline
</fb:login-button>
or
<fb:add-to-timeline></fb:add-to-timeline>
<form>
<input type="button" value="Publish" onclick="postArticle()" />
</form>
the solution was :
<fb:login-button onlogin='postlike()' perms="email,publish_actions,user_actions.video">Timeline</fb:login-button>