Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Wordpress facebook page tab - cant echo simple graph api info WordPress


I am building a facebook page tab, but feeding in gravity froms from a wordpress install on the same server.

The form is an ajax gravity form, which is echo'ed in the index.php file via do_shortcode.

I am getting the wordpress link via calling the wp-load.php

The problem I am having is more facebook related. The problem is I cant seem to echo the current facebook user name.

You will see I'm trying to echo $user['name']; in various places in the code below, but I cannot for the life of me get facebook output any graph data :/

Everything else works, my gravity form works, my signed in request variable works, the facebook sdk appears to be loading ok, my channel file is in place, and I am previewing my tab within facebooks tab iframe.

But I just can't retrieve the graph data - and I have checked all my app secret/app ID about a million times. I am using the newest SDK found on git hub. Here is where I took the source from...

Can any one please test my code below in a facebook app. Technically I should not have to fill any of the app canvas urls in the facebook app settings, just my page tab settings. But I did both settings to be sure. Please see [[LINK href=""]]screenshot[[/LINK]] of my settings here... [[LINK href=""]][[/LINK]]

Thanks in advance for anyhelp to see where I am going wrong.


define('WP_USE_THEMES', false);

$fb_app_id = '000000000000000';
$fb_secret = '000000000000000000000000000000';

require 'facebook-php-sdk-98f2be1/src/facebook.php';

$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true

// Get User ID
$user = $facebook->getUser();

if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = null;

add_filter('gform_field_value_facebook_name', 'facebook_name_population_function');
function facebook_name_population_function($value){
return $user['name'];

$signedRequest = $facebook->getSignedRequest();

<!DOCTYPE html>
<html xmlns:fb="">


<meta name="robots" content="noindex, nofollow">

<meta property="fb:app_id" content="<?php echo $fb_app_id ?>" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title><?php echo $user['name']; ?>, Feedback Form</title>

<link rel="profile" href="" />
<link rel="shortcut icon" href="<?php bloginfo('url'); ?>/favicon.ico" />

<link rel="stylesheet" type="text/css" media="all" href="style.css" />

<script src=""></script>



<h1><?php echo $user['name']; ?>, Feedback Form</h1>

<?php if ( ( !$signedRequest['page']['liked'] ) == 1 ) {

echo '<p>You must like us!</p>';

} else {

echo do_shortcode('[gravityform id="2" name="Feedback Form" title="false" ajax="true"]');

} ?>

<div id="fb-root"></div>


window.fbAsyncInit = function() {
appId: '<?php echo $fb_app_id; ?>',
channelUrl : '//', // Channel File
cookie: true,
xfbml: true,
oauth: true,
status: true // check login status
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +

<?php if ( ( $signedRequest['page']['liked'] ) == 1 ) { ?>

$(document).ready(function($) {


$(document).bind('gform_post_render', function(){




<?php } ?>



Answers (2)


Michael Caputo answers:

Just curious how long you've waited for it to work? I'm not sure, but there may be a delay from when you set up your Facebook app.

Michael Caputo comments:

Also could this line be the problem?
channelUrl : '//', // Channel File

Michael Caputo comments:

Scratch that, I see now that you've replaced your URL with example.

Josh Cranwell comments:

Set up the app on the friday.

Graph API should be instant I thought - never had this problem in past :(

This how facebook generally ask you to the channel file - I changed my URL to //

My channel file consists of...

$cache_expire = 60*60*24*365;
header("Pragma: public");
header("Cache-Control: max-age=".$cache_expire);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');
<script src="//"></script>

Michael Caputo comments:

Just found this, might be related:

Josh Cranwell comments:

Not sure if it is..

$signedRequest = $facebook->getSignedRequest(); this should work better than this surely?

My signed in request is working tho, If someone has not liked the pages, then they have to like it before the form can be entered.

I tried using this instead but still no graph data echo'ing???

$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);


Arnav Joy answers:

try getting the values return by facebook by

<?php print_r( $user ) ;?>

where you are using echo $user['name'] ,

also try this

<?php 'I am got printed here'. echo $user['name'] ?>

tell me the output of both the result.

Josh Cranwell comments:

Hello Arnav,

Sorry I made a mistake in the my code above.

It should be this <?php echo $user['name']; ?> - but it echo's nothing?

I tried this... <?php print_r( $user ) ;?> but this does not work either?

Have you got a facebook app you can test it with, shall I make you admin of my app