open graph and tpl file - facebook

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>

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:

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>

send email after facebook comment is posted

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>';`

facebook login-button - registration-url doesn't work

I'm trying to integrate the facebook registration-login plugin in my site.
Following is an example that is trying just to implement the login button.
According to documentation:
"If the user has not registered for your site, they will be redirected to the URL you specify in the registration-url parameter."
However this doesn't happen. When the user clicks on the login button and he isn't registered in my site yet, the same page, with the login button, reloads.
<?php
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
(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'));
window.fbAsyncInit = function() {
FB.init({
appId : 'MY APP ID',
channelUrl : 'MY CHANNEL URL',
status : true,
cookie : true,
oauth : true,
xfbml : true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
</script>
<fb:login-button
registration-url="...my site's address/test.php"
on-login="console.log(arguments)"
/>
</body>
Go to this site: https://www.facebook.com/appcenter/my and remove your app and try again! You will see, it works! ;)

Detecting if a user clicked on Facebook Like button

It looks like:
FB.Event.subscribe('edge.create', function(href, widget) {
alert("Hi");
});
works for everybody except me!
Here is my code:
<html xmlns:fb="https://www.facebook.com/2008/fbml">
.
.
.
<body>
<div id="section1">
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId :'xxx',
status : true,
cookie : true,
xfbml : true,
oauth : true
});
FB.Event.subscribe('edge.create', function(href, widget) {
alert("Hi");
});
});
(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>
<fb:like href="mysite" send="false" width="450" show_faces="false" font="tahoma"></fb:like>
</div>
I just need a simple way to check if the like button was clicked to show a form on the page! Any Suggestions? Thanks
You can even detect multiple likes on the same page. We use this quite often, check the below snippet.
window.fbAsyncInit = function() {
FB.init({appId: 'YOUR_FACEBOOK_APP_ID', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('edge.create', function(href, widget) {
// START: LOGIC For detecting multiple likes on the same page
if(href == "LINK_1_ON_THEPAGE') {
alert('User Like is for Link1');
} else if (href == "LINK_2_ON_THEPAGE') {
alert('User Like is for Link2');
}
// END: LOGIC For detecting multiple likes on the same page
});
};