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
Related
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);
}
?>
I'm trying to figure out the basics of the facebook php sdk. I'm using the pretty simple code below...
<?php
include 'facebook.php';
$app_id = "my_id";
$app_secret = "my_secret";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$userId = $facebook->getUser();
echo $userId;
$userInfo = $facebook->api("/$userId");
echo $userInfo['name'];
?>
When I ask for the $userId with
$userId = $facebook->getUser();
echo $userId;
I get the correct value. However when I try to take the next step and retrieve the logged in user's name with :
$userInfo = $facebook->api("/$userId");
echo $userInfo['name'];
nothing is returned. Does anyone see my error? Thanks!
'/$userId' will actually use the literal string /$userId. You probably want "/$userId" or '/me'
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");
}
}
?>
require 'facebook.php';
$app_id ="11111111111111111";
$app_secret = "11111111111111111111111111";
$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"];
$name = $signed_request["user"]["name"];
According to the facebook docs, the user property is
A JSON object containing the locale string, country string and the age object (containing the min and max number range of the age) for the current user.
Note the lack of any mention of a name in there.
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");