I am trying to make a simple fangate Facebook app, but i get stuck.
The page simply doesnt show - its blank.
I found a code on internet and implemented it (also downloaded facebook sdk from github)
The Facebook Page URL (http) and Secure (https) are correct.
If I link index.php the page is blank, if I link the prelike.php or reveal.php the content is shown.
Does anyone know where might be the problem?
link to the facebook app :
https://www.facebook.com/pages/Testna-stran/136388943218474?id=136388943218474&sk=app_744205652262463
<?php
require 'facebook.php';
$app_id = "xxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
// The following statement does a test of $like_status and chooses which page to display to the visitor
if ($like_status) {$a = file_get_contents("reveal.php");
echo ($a);
}
else {$a = file_get_contents("prelike.php");
echo ($a);
}
?>
Related
I am trying to create a facebook fangate tab.
i am using this code
<?php
// create the Facebook Graph SDK object
require_once('facebook.php');
$facebook = new Facebook(array(
'appId'=>'xxx', // replace with your value
'secret'=>'xxxxx' // replace with your value
));
$signedRequest = $facebook->getSignedRequest();
// Inspect the signed request
if($signedRequest['page']['liked'] == 1){
echo 'pageid ' + $signed_request["page"]["id"];
include('like.php');
} else {
echo 'pageid ' + $signed_request["page"]["id"];
include('noLike.php');
}
?>
But it dosnt seem to work, the page id displays as zero. it always displays the nolike.php file.
I have also tried this code
$app_id = "xxx";
$app_secret = "xxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
?>
<?php
if($like_status){
include('like.php');
}else{
include('noLike.php');
}
?>
This also only shows the noLike.php file
here is a like to the page
http://www.facebook.com/pages/BigDawg-Labs/166258126793251?sk=app_280260608708912
Do you have any ideas why i cannot $signed_request["page"]["liked"] always evaluates to false
I'm creating an app for a client that requires French content to be displayed to French speaking Facebook users. If the user is not French speaking, English content should be displayed. This needs to work in conjunction with the fan-gating.
This is what I have, however it's not working. The fan gate is, but the French content is not displaying (yes, I changed my language in my Facebook settings to French).
To summarize, if the user is French speaking, show fan and non-fan French content, else show default English content.
Here is the code:
<?php
require 'facebook.php';
$app_id = "XXX";
$app_secret = "XXX";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
$languageFR = $signed_request["user"]["fr_CA"];
if ($like_status) {
if ($languageFR) {
include("fans_french.php");
}
else {
include("fans_english.php");
}
}
else {
if ($languageFR) {
include("nonfans_french.php");
}
else {
include("nonfans_english.php");
}
}
?>
Shouldn't your line about the language be:
$languageFR = ($locale == "fr_CA");
Or even better, shouldn't you be looking at ["user"]["languages"], and not the locale?
(Posted solution on behalf of the question author to move it to the answer space).
Here is an updated and working script:
<?php
require 'facebook.php';
$app_id = "XXX";
$app_secret = "XXX";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
$languageFR = ($locale == "fr_CA");
if ($like_status) {
if ($languageFR) {
include("fans_french.php");
}
else {
include("fans_english.php");
}
}
else {
if ($languageFR) {
include("nonfans_french.php");
}
else {
include("nonfans_english.php");
}
}
?>
I can't figure it out and it's hard to Google:
My iframe produces a "1" just before the
but I can't figure out why and where it comes from.
http://www.quepasa.in-town.nl/facebook/
My code:
require 'fb-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
if ($like_status) {
echo include("page-revealed.php");} else {echo include("page-signup.php");}
The revealed and signup have not more then this and temporary deleting everything didn't help.
Does anyone know where this is coming from?
This is because you are doing an "echo" on an include. Remove the echo and just have it as
if ($like_status) {
include("page-revealed.php");} else { include("page-signup.php");}
And you should be good.
you don't need to echo include, just include basically
Just do:
include("http://www.mysite.net/script.php");
Or:
echo file_get_contents("http://www.mysite.net/script.php");
I've used this code for dozens of reveal tabs and now they've stopped working. I've found a fix for the https pages, but that fix doesn't work on http pages. Please see the code below and any specific help would be great.
<?php
require 'facebook.php';
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
// If a fan is on your page
if ($like_status) {
$a = file_get_contents("yourlikepage.html");
echo ($a);
} else {
// If a non-fan is on your page
$a = file_get_contents("yournolikepage.html");
echo ($a);
}
?>
I am by no means a coder. Please be specific in your response with actual code fixes as otherwise it's likely your answer, as awesome as it'll be, will soar over my limited brain.
Thanks!
As one limited brain to another, I just wanted to double check that you are actually entering in your App ID and App Secret. I hope this doesn't seem like a stupid question - you'd be surprised!
I'm unable to get custom parameters send to my facebook fan page tab.
I'm using php and is passing like this:
http://www.facebook.com/pages/{page-name}/?sk=APP_ID&pass=1
but I'm unable to read the parameter pass
Sreejith
Facebook passes in your data as part of the signed_Request data.
Here is how you would retrieve it using PHP:
<?php
require 'facebook.php';
$app_id = "YOUR APP ID HERE";
$app_secret = "YOUR SECRET KEY HERE";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// THE MAGIC SAUCE
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$like_status = $signed_request["page"]["liked"];
// HERE IS A STRING OF YOUR APP DATA.
$app_data = $signed_request["app_data"];
echo '$app_data = '.$app_data;
?>
This example requires the Facebook PHP api and will write your app_data into the browser window where you can marvel in all its glory.
Oh wow, I didn't know about the app_data parameter.Here's another method for whatever it's worth:
http://iamskwerl.com/tech/2011/11/passing-query-variables-to-facebook-fan-page-tabs/
There is a solution available although I have not tried it but hope it works
http://ikorolchuk.blogspot.com/2011/03/facebook-fan-page-pass-parameter-to.html