0

I have performed the below and yet even as a fan, it is only saying "NON-FAN".
I have uploaded the facebook.php file and added my app settings to which I think are correct. What have I done wrong?

My app settings are as follows:

Canvas URL: http://www.mysite.com/myapp/  
Secure Canvas URL: https://www.mysite.com/myapp/  
Page Tab URL: http://www.mysite.com/myapp/index.php  
Secure Page Tab URL: https://www.mysite.com/myapp/index.php

I've coded my index.php file on my server as follows:

<?php
require 'facebook.php';
//uploaded into same directory as index.php

$app_id = "myappid";
$app_secret = "myappsecret";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));

$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my app</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript">
window.fbAsyncInit = function() {
FB.Canvas.setSize();
}
// Do things that will sometimes call sizeChangeCallback()
function sizeChangeCallback() {
FB.Canvas.setSize();
}
</script>

<base target='_blank' />
</head>

<body>

<div id="container">

<?php if ($like_status) { ?>
FAN
<?php } else { ?>
NON-FAN
<?php } ?>

</div>

<div id="fb-root"></div>
<script src="https://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'myappid',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});

window.fbAsyncInit = function() {
FB.Canvas.setAutoResize();
}
</script>
<script>
FB.Event.subscribe('edge.create',
function(response){
top.location.href = 'myappurl';
});
</script>

</body>
</html>
iCeR
  • 71
  • 1
  • 2
  • 10

2 Answers2

0

Method described here, usualy does the trick for finding out, whether user is fan of page or not.

If you want to do it your way, could you please provide var_dump($like_status), after it's been assigned some value?

Community
  • 1
  • 1
Darvex
  • 3,624
  • 2
  • 23
  • 39
  • thank you - I just can't seem to find the "OAuth 2.0 for Canvas" advanced option? – iCeR Jul 12 '12 at 19:03
  • it's on by default now if i remember correctly (the answer comes from early 2011, might've not been enabled for all apps back then) – Darvex Jul 12 '12 at 19:04
  • var_dump($like_status); returns NULL :( – iCeR Jul 12 '12 at 19:05
  • Also when trying this approach: http://facebook.stackoverflow.com/questions/5329818/seamless-way-to-check-if-user-likes-page/5331541#5331541 I get "signed_request was not found!" :( – iCeR Jul 12 '12 at 19:07
  • Okay, where are you testing it? Because you will get signed request only when you're trying it on facebook (opening your tab there) – Darvex Jul 12 '12 at 19:10
  • Yep testing it from opening the tab, ie: http://www.facebook.com/pages/mypage/0000000000?sk=app_0000000000000 – iCeR Jul 12 '12 at 19:13
  • I'd dare to say that something might be wrong with app settings in that case. I recently made fan gate app myself, didn't have problems with that. – Darvex Jul 12 '12 at 19:17
  • Hmmm. Ok so were the settings any different to that of my original post? – iCeR Jul 12 '12 at 19:19
  • actully yes, i see your page tab and secure page tab are pointing at index.php file. remove that, leave only http://www.mysite.com/myapp/, and https for secure one, see if that helps – Darvex Jul 12 '12 at 19:22
  • Unfortunately no difference :( – iCeR Jul 12 '12 at 19:31
  • that is odd, since both ->getSignedRequest() and function i gave link to are not working, i guess your web part is not getting signed request. If it's not the setup issue, i'm not really sure what it could be. I'd suggest experimenting a little more with settings, and reading about [signed request](http://developers.facebook.com/docs/authentication/signed_request/) – Darvex Jul 12 '12 at 19:39
0

Keep in mind, that the signed_request parameter is only available on first page load into the iframe – once you start navigating within your app, there will be no more signed_request. (So you have to save the signed_request or the like status into the session f.e., once you’ve got it.)

If you’re not getting any data even on first load, then var_dump the contents of the $_REQUEST variable, to see if the value is there. If it is, then most likely your app secret is wrong – because Facebook::getSignedRequest will return null if it is not able to validate the signed request by calculating the right hash using the app secret. Please double check if your app secret is really correct.

CBroe
  • 91,630
  • 14
  • 92
  • 150
  • Triple checked and still no luck- all details are 100% correct. It only has one page to load, index.php :/ – iCeR Jul 12 '12 at 21:23