A "1" output with Facebook php-sdk - 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");

Related

Facebook Fangate

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);
}
?>

How to get fan-gate implemented for php Facebook SDK

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

Display Facebook tab content for different user languages

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");
}
}
?>

Reveal tab index.php code that used to work doesn't now. How do I fix?

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!

Facebook php sdk Retrieve friendlist issue

I got a Facebook php sdk Retrieve friendlist problem. Here is my basic code...
<?php
require_once 'fb-sdk/src/facebook.php';
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => 'xxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxx',
'cookie' => true,
));
$accessToken = $facebook->getAccessToken();
$session = $facebook->getSession();
$uid = $facebook->getUser();
//echo "https://graph.facebook.com/".$uid."/friends/?access_token=".$accessToken;
$frnd = $facebook ->api('/me/friends?access_token='.$accessToken);
echo $frnd["data"][0]["name"];
?>
But it returns a peculiar output.

Where is the problem?
You dont have to add the access_token, when you query for the friends. The Facebook-Api takes care of that. This is my code, which works for me:
$facebook = new Facebook(array(
'appId' => 'xxxxxxxx',
'secret' => 'xxxxxxx',
'cookie' => true,
));
// $session is only != null, when you have the session-cookie, that is set by facebook, after the user logs in
$session = $facebook->getSession();
// you dont get a list of friends, but a list, which contains other friendlists
$friendsLists = $facebook->api('/me/friends');
// Save all Friends and FriendConnections
foreach ($friendsLists as $friends) {
foreach ($friends as $friend) {
// do something with the friend, but you only have id and name
$id = $friend['id'];
$name = $friend['name'];
}
}
 is BOM header:
See: http://en.wikipedia.org/wiki/Byte_order_mark
(you should encode your file as uff-8 without bom)
This means your code isn't outputting anything.
$friends = $facebook->api('me/friends');
//print_r($friends['data']);
print_r("Number of friends: ". count($friends['data']));
foreach ($friends['data'] as $key=>$friendList) {
echo "<br/>".$key." ".$friendList['name']."<img src='https://graph.facebook.com/".$friendList['id']."/picture' width='50' height='50' title='".$friendList['name']."' />";
}
//get user basic description using graph api
$friends = $facebook->api('me?fields=friends');
print_r("Number of friends: ". count($friends['friends']['data']));
foreach ($friends['friends']['data'] as $key=>$friendList) {
echo "<br/>".$key." ".$friendList['name']."<img src='https://graph.facebook.com/".$friendList['id']."/picture' width='50' height='50' title='".$friendList['name']."' />";
}
?>

Categories