Facebook app canvas page: Can't see FBML-like button - facebook

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com /2008/fbml">
<head>
<style>
body { font: 12px Calibri; }
</style>
</head>
<body>
<fb:like href="http://www.facebook.com/pages/Trololo/236069739747588?sk=app_229260073773183" width="450" show_faces="false" font="arial"> </fb:like>
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {
//Does not like
} else {
//Likes
}
?>
<div id="fb-root"></div><script src="http://connect.facebook.net/se_SV /all.js#appId=113202612108305&xfbml=1"></script>
<script type="text/javascript">
$(function() {
FB.init({appId: '229260073773183', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('edge.create', function(response) {
//clicked "like"
});
FB.Event.subscribe('edge.remove', function(response) {
//clicked "unlike"
});
});
</script>
</body>
</html>
Test-app url: http://www.facebook.com/pages/Trololo/236069739747588?sk=app_229260073773183
My problem: Can't see the like-button. Did I miss something?
Thanks!

Try putting the fb-root before the php block AND the fb:like element.
<body>
<div id="fb-root"></div><script src="http://connect.facebook.net/se_SV /all.js#appId=113202612108305&xfbml=1"></script>
<fb:like href="http://www.facebook.com/pages/Trololo/236069739747588?sk=app_229260073773183" width="450" show_faces="false" font="arial"> </fb:like>

Related

facebook login in a cross-domain iframe

Note the following 3 files. If all are in the same domain, everything works fine. However, if the parent file is on a different domain, then the facebook cookie does not seem to pass between the two son iframes. I need it to work that way... any advice?
File zzzfbparent.html
<!DOCTYPE html>
<html>
<body>
<iframe src="<domain and directory>/zzzfb1.html" style="width:400px; height:200px;"></iframe>
</body>
</html>
File zzzfb1.html
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<input type="button" value="Login" onClick="doLogin();"></input>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'XXXXXXXXXXXXXXXX',
status: false,
cookie: true,
xfbml: false
});
};
(function(){
if (document.getElementById('facebook-jssdk')) {return;}
var fjs = document.getElementsByTagName('script')[0];
var js = document.createElement('script');
js.id = 'facebook-jssdk';
js.src = '//connect.facebook.net/he_IL/all.js';
fjs.parentNode.insertBefore(js, fjs);
}());
function doLogin() {
FB.login(function(respLogin) {
location.replace('zzzfb2.php');
}, {scope: 'email'});
}
</script>
</body>
</html>
File zzzfb2.php
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
));
$user = $facebook->getUser();
?>
<!DOCTYPE html>
<html>
<body>
<?php echo '$user='.$user ?>
</body>
</html>
After posting the question I found a thorough discussion about the problem (which relates to "third party cookies" in Internet Explorer) over here:
Cookie blocked/not saved in IFRAME in Internet Explorer

website on localhost not loading on refresh once the url is updated through window.pushState

My website is not loading on refreshing the page once the url is updated by window.pushState. My website is saved on this location: http://localhost/ajax.test/index.html
but after clicking the link with href="1" the url changes to http://localhost/ajax.test/1
.. here is the source code:
html:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="myscript.js"></script>
</head>
<body>
<ul>
<li class="list" id="1">home</li>
<li class="list" id="2">project</li>
<li class="list" id="3">about</li>
</ul>
<div id="dynamic"></div>
</body>
</html>
jQuery:
var url = 0;
var state=0;
$(document).ready(function(){
$('ul a').click(function(e) {
e.preventDefault();
alert(e.target);
url = $(this).attr("href");
history.pushState({page:url}, url,url);
loadContent(url);
});
});
$(window).bind('popstate', function(e){
state = event.state;
if(state){
loadContent(state.page);
}else{
loadContent("home");
}
});
function loadContent(currentPage){
alert(currentPage);
$.ajax({
type: "GET",
url: "ajax.php",
data: "id="+currentPage,
success: function(data){
$('#dynamic').html(data);
}
});
};
php:
<?php
$response = $_GET['id'];
if($response=="1")
{
echo "<h1>You loaded HOME</h1>";
}
else if($response=="2")
{
echo "<h1>You loaded PROJECT</h1>";
}
else if($response=="3")
{
echo "<h1>You loaded ABOUT</h1>";
}
?>

Facebook App Like server error?

I have a sample app that has a 'Like' button. It works before but now it doesn't.
I've tested this on jsfiddle.net before and it works too. But after I've uploaded my files on a server it has a bug. The 'Like' button pops up and then has this error:
https://www.facebook.com/plugins/error/confirm/like?iframe_referer=https%3A%2F%2Fns2383.hostgator.com%2F~caryucla%2Fbpcontest%2FHTML%2FContestHome.php%2F&secure=true&plugin=like&return_params=%7B%22api_key%22%3A%22301719366592208%22%2C%22locale%22%3A%22en_US%22%2C%22sdk%22%3A%22joey%22%2C%22ref%22%3A%22.UKWNYwbFB-8.like%22%2C%22channel_url%22%3A%22https%3A%2F%2Fs-static.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D17%23cb%3Df13bb8c95%26origin%3Dhttps%253A%252F%252Fns2383.hostgator.com%252Ff2bf9f920%26domain%3Dns2383.hostgator.com%26relation%3Dparent.parent%22%2C%22href%22%3A%22https%3A%2F%2Fwww.facebook.com%2Fpages%2FDummy-Page-for-Testing%2F375795832160%22%2C%22node_type%22%3A%22link%22%2C%22width%22%3A%2290%22%2C%22font%22%3A%22arial%22%2C%22layout%22%3A%22button_count%22%2C%22colorscheme%22%3A%22light%22%2C%22action%22%3A%22like%22%2C%22show_faces%22%3A%22false%22%2C%22send%22%3A%22false%22%2C%22extended_social_context%22%3A%22false%22%2C%22ret%22%3A%22sentry%22%2C%22act%22%3A%22connect%22%7D
I've already read this article on SO already and followed the answer but still didn't work. Any views on this error?
PS:
I am all in all fairly new to this.
and here's the sample code I'm using:
<?php
include_once("../incs/dbcon.php");
require_once('AppInfo.php');
require_once('utils.php');
require_once('../sdk/src/facebook.php');
//This gets the signed_request from FB which checks the 'liked' status on the current page
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
$app_data = isset($data["app_data"]) ? $data["app_data"] : '';
$_REQUEST["fb_page_id"] = $data["page"]["id"];
$access_admin = $data["page"]["admin"] == 1;
$has_liked = $data["page"]["liked"] == 1;
$facebook = new Facebook(array(
'appId' => AppInfo::appID(),
'secret' => AppInfo::appSecret(),
));
$user_id = $facebook->getUser();
if ($user_id) {
try {
// Fetch the viewer's basic information
$basic = $facebook->api('/me');
} catch (FacebookApiException $e) {
// If the call fails we check if we still have a user. The user will be
// cleared if the error is because of an invalid accesstoken
if (!$facebook->getUser()) {
header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
exit();
}
}
// This fetches some things that you like . 'limit=*" only returns * values.
// To see the format of the data you are retrieving, use the "Graph API
// Explorer" which is at https://developers.facebook.com/tools/explorer/
$likes = idx($facebook->api('/me/likes?limit=4'), 'data', array());
// This fetches 4 of your friends.
$friends = idx($facebook->api('/me/friends?limit=4'), 'data', array());
// And this returns 16 of your photos.
$photos = idx($facebook->api('/me/photos?limit=16'), 'data', array());
// Here is an example of a FQL call that fetches all of your friends that are
// using this app
$app_using_friends = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT uid, name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1'
));
}
// Fetch the basic info of the app that they are using
$app_info = $facebook->api('/'. AppInfo::appID());
$app_name = idx($app_info, 'name', '');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:fb="http://ogp.me/ns/fb#">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo he($app_name); ?></title>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# bpapptestbpapptest: http://ogp.me/ns/fb/bpapptestbpapptest#">
<meta property="fb:app_id" content="301719366592208" />
<meta property="og:type" content="bpapptestbpapptest:video" />
<meta property="og:url" content="Put your own URL to the object here" />
<meta property="og:title" content="Sample Video" />
<meta property="og:image" content="https://ns2383.hostgator.com/~caryucla/bpcontest/Images/BPIcon.png" />
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# object: http://ogp.me/ns/object#">
<meta property="fb:app_id" content="301719366592208" />
<meta property="og:type" content="object" />
<meta property="og:url" content="Put your own URL to the object here" />
<meta property="og:title" content="Sample Object" />
<meta property="og:image" content="https://ns2383.hostgator.com/~caryucla/bpcontest/Images/BPIcon.png" />
<link href="https://ns2383.hostgator.com/~caryucla/bpcontest/CSS/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function logResponse(response) {
if (console && console.log) {
console.log('The response was', response);
}
}
$(function(){
// Set up so we handle click on the buttons
$('#postToWall').click(function() {
FB.ui(
{
method : 'feed',
link : $(this).attr('data-url')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
logResponse(response);
}
}
);
});
$('#sendToFriends').click(function() {
FB.ui(
{
method : 'send',
link : $(this).attr('data-url')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
logResponse(response);
}
}
);
});
$('#sendRequest').click(function() {
FB.ui(
{
method : 'apprequests',
message : $(this).attr('data-message')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
logResponse(response);
}
}
);
});
});
</script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '301719366592208', // App ID
channelUrl : ' https://ns2383.hostgator.com/~caryucla/bpcontest/HTML/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true,
xfbml : true // parse XFBML
});
// Listen to the auth.login which will be called when the user logs in using the Login button
//FB.Event.subscribe('auth.login', function(response) {
// We want to reload the page now so PHP can read the cookie that the
// Javascript SDK sat. But we don't want to use
// window.location.reload() because if this is in a canvas there was a
// post made to this page and a reload will trigger a message to the
// user asking if they want to send data again.
//window.location = window.location;});
//FB.Canvas.setAutoGrow();
FB.Event.subscribe('auth.authResponseChange', function(response) {
alert('The status of the session is: ' + response.status);});
};
</script>
<div id="fb-root"></div>
<script>(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&appId=301719366592208";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<link rel="stylesheet" href="https://ns2383.hostgator.com/~caryucla/bpcontest/CSS/jquery-ui.css" /><!--http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css-->
<script src="https://ns2383.hostgator.com/~caryucla/bpcontest/javascript/jquery-1.8.2.js"></script><!--http://code.jquery.com/jquery-1.8.2.js-->
<script src="https://ns2383.hostgator.com/~caryucla/bpcontest/javascript/jquery-ui.js"></script><!--http://code.jquery.com/ui/1.9.1/jquery-ui.js-->
<script src="https://ns2383.hostgator.com/~caryucla/bpcontest/javascript/jquery.bgiframe-2.1.2.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
FB.Event.subscribe('edge.create',
function(response) {
$(function onclick() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height:250,
modal: true,
buttons: {
"Register?": function() {
window.location="https://ns2383.hostgator.com/~caryucla/bpcontest/HTML/RegForm.php";
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
}
);
</script>
</head>
<body>
<div id="Content">
<div id="header">
<div id="LogoDiv">
<img id="logo" src=" https://ns2383.hostgator.com/~caryucla/bpcontest/Images/Bp logo.png"></div><!--end of LogoDiv-->
<div id="LogoTextDiv">
<p id="LogoText">Fashion & Compassion Contest</p></div><!--end of LogoTextDiv-->
</div><!--end of header-->
<div id="DummyRow1"></div><!--end of DummyRow-->
<div id="BGForm">
<div id="Home">
<div id="Welcome">
<h1 id="WelcomeText">Welcome to Banana Peel's Fashion and Compassion Contest App!</h1>
</div><!--end of Welcome-->
<div id="HomeMechanics">
<h2>Contest Mechanics:</h2>
<div id="FBLogIn" class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1" autologoutlink="true" onlogin="OnRequestPermission();"></div><!--end of FBLogIn div-->
<p id="Mec">To join the contest, Participants must first Log In through Facebook and LIKE Banana Peel's Facebook Fan Page. After liking the page you will be able to click the registration link button.</p>
<div id="LikeBox">
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count" addthis:url="https://www.facebook.com/pages/Dummy-Page-for-Testing/375795832160" addthis:title="Banana Peel Page" onclick="onclick()"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_pinterest_pinit"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<div id="dialog-confirm">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin: 0 7px 20px 0;"></span>Thank you for liking our page!</p>
</div><!--end of dialog-confirm div--><!--end of class addthis_toolbox addthis_default_style-->
<script type="text/javascript" src="https://ns2383.hostgator.com/~caryucla/bpcontest/javascript/addthis_widget.js"></script>
</div><!--end of LikeBoxhttp://s7.addthis.com/js/300/addthis_widget.js#pubid=xa-50a0584951afe01c-->
</div><!--end of HomeMechanics-->
<div id="ContestantsBG">
<img src="https://ns2383.hostgator.com/~caryucla/bpcontest/Images/BPpic.jpg"/>
</div><!--end of ContestantBG-->
<div id="GalleryButton">
<a id="BackLink" href="../HTML/ContestantGallery.php"><input type="button" value="VIEW GALLERY OF CONTESTANTS"></a>
</div><!--end of GalleryButton-->
</div><!--end of Home-->
</div><!--end of BGForm-->
</div><!--end of Content-->
</body>
</html>
This message is what Facebook use to stop Like-jacking and prevent spam. It can also appear if the Like button has been added to a website / domain for the first time. Give it time and the message will disappear once Facebook is satisfied that your site isn't doing any of the above things.

Facebook Reveal Without PHP

I found some code on here for NON-PHP Revealing HTML when the Like button is clicked however, not working for me. The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
body {
width:520px;
margin:0; padding:0; border:0;
font-family: verdana;
background:url(repeat.png) repeat;
margin-bottom:10px;
}
p, h1 {width:450px; margin-left:50px; color:#FFF;}
p {font-size:11px;}
#container_notlike, #container_like {
display:none
}
</style>
<script type="text/javascript" src="/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
FB.login(function (response) {
if (response.session) {
var user_id = response.session.uid;
var page_id = "167544069999229";
var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function (rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
$("#container_like").show();
//here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.
} else {
$("#container_notlike").show();
//and here you could get the content for a non liker in ajax...
}
});
} else {
// user is not logged in
}
});
});
</script>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId: '270349276366373',
status: true,
cookie: true,
xfbml: true
});
</script>
<div id="container_notlike">
YOU DONT LIKE
</div>
<div id="container_like">
YOU LIKE
</div>
</body>
</html>
I have changed the APPID and PageID as necessary but not working and it keeps trying to bring up a pop up window.
It will eventually contain dynamic content in vb.net aspx file, so PHP isnt available to me.
Any ideas, can it be done server side through a SOAP or REST request?
you have to wait until the script is loaded and the FB va is init, try this flow...
if you have problem with login
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// fired when script is loaded
window.fbAsyncInit = function() {
FB.init({
appId : '', // App ID
channelUrl : '', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
//do some stuff here (Login)
};
// Load the SDK Asynchronously
(function(d){
var js;
var id = 'facebook-jssdk'
var 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/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>

FB.Canvas.setSize simply fails after a refresh? (facebook iframe application)

I've created a facebook connect application, iframe. I'm using it under apps.facebook.com/app-name.
It seems that after a refresh, the setSize() method simply fails. sometimes works, sometimes doesn't... (under latest Firefox and IE) is there a solution for that? would you recommend using the old API instead?
testcase:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>test</title>
<meta name="description" content="test">
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'XXXXXXXXX', status: true, cookie: true, xfbml: true});
FB.Canvas.setSize({ width:760,height:3000 });
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<div style="height:2000px;background:blue;width:760px;">
</div>
</body>
</html>
if for some reason window.name is set the FB.setAutoSize wont work, http://bugs.developers.facebook.net/show_bug.cgi?id=19720 in my case its connected somehow to jquery $.data
window.fbAsyncInit=function(){
FB.Canvas.setSize = function(b) {
if (typeof b!="object")
b={};
b=b||{};
if (b.width==null||b.height==null)
b=FB.copy(b,FB.Canvas._computeContentSize());
b=FB.copy(b,{frame:'iframe_canvas'});
if (FB.Canvas._lastSize[b.frame]) {
var a=FB.Canvas._lastSize[b.frame].height
if(FB.Canvas._lastSize[b.frame].width==b.width&&(b.height<=a&& (Math.abs(a-b.height)<=16)))
return false;
}
FB.Canvas._lastSize[b.frame]=b;FB.Arbiter.inform('setSize',b);
return true;
}
FB.init({
appId:"<?php echo FB_APP_ID; ?>",
status:true,
cookie:true,
xfbml:true
});
FB.Canvas.setAutoResize()
};