Fatal error: Call to a member function fql_query() on a non-object in facebook php

Hi there,

I have a problem with my php script which im developing for my facebook application this is my php code


$app_name = "GAME";
$app_url = "http://apps.facebook.com/Game/"; // Assumes application is at http://apps.facebook.com/app-url/
$invite_href = "invite.php"; // Rename this as needed
if(isset($_POST["ids"])) {
	echo "<center>Thank you for inviting ".sizeof($_POST["ids"])." of your friends on <b><a href=\\"http://apps.facebook.com/".$app_url."/\\">".$app_name."</a></b>.<br><br>\
";
	echo "<h2><a href=\\"http://apps.facebook.com/".$app_url."/\\">Click here to return to ".$app_name."</a>.</h2></center>";
} else {
	// Retrieve array of friends who've already authorized the app.
	$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.') AND is_app_user = 1';
	$_friends = $facebook->api_client->fql_query($fql);
	// Extract the user ID's returned in the FQL request into a new array.
	$friends = array();
	if (is_array($_friends) && count($_friends)) {
		foreach ($_friends as $friend) {
			$friends[] = $friend['uid'];
		}
	}

	// Convert the array of friends into a comma-delimeted string.
	$friends = implode(',', $friends);

	// Prepare the invitation text that all invited users will receive.
	$content =
		"<fb:name uid=\\"".$user."\\" firstnameonly=\\"true\\" shownetwork=\\"false\\"/> has started using <a href=\\"http://apps.facebook.com/".$app_url."/\\">".$app_name."</a> and thought it's so cool even you should try it out!\
".
		"<fb:req-choice url=\\"".$facebook->get_add_url()."\\" label=\\"Put ".$app_name." on your profile\\"/>";

?>
<fb:request-form
	action="<? echo $invite_href; ?>"
	method="post"
	type="<? echo $app_name; ?>"
	content="<? echo htmlentities($content,ENT_COMPAT,'UTF-8'); ?>">

	<fb:multi-friend-selector
		actiontext="Here are your friends who don't have <? echo $app_name; ?> yet. Invite whoever you want -it's free!"
		exclude_ids="<? echo $friends; ?>" />
</fb:request-form>
<?PHP
}

The error i am actually getting is

Fatal error: Call to a member function fql_query() on a non-object in /home/willbcco/public_html/facebook/invite.php on line 11

On Line 11 i have this


$_friends = $facebook->api_client->fql_query($fql);

What is wrong with the above code how can i get rid of the fql query error?

Thanks,William

You’re missing a definition for $facebook

It’ll look something like this:


$facebook = new Facebook($api_key, $secret);

I get this the result is this

Notice: Undefined variable: user in /home/willbcco/public_html/facebook/invite.php on line 11

Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Parser error: unexpected ‘)’ at position 70.’ in /home/willbcco/public_html/facebook/php/facebookapi_php5_restlib.php:3112 Stack trace: #0 /home/willbcco/public_html/facebook/php/facebookapi_php5_restlib.php(1025): FacebookRestClient->call_method(‘facebook.fql.qu…’, Array) #1 /home/willbcco/public_html/facebook/invite.php(12): FacebookRestClient->fql_query(‘SELECT uid FROM…’) #2 {main} thrown in /home/willbcco/public_html/facebook/php/facebookapi_php5_restlib.php on line 3112

The Facebook Development Forum may well be better placed to resolve these issues for you.

okay thanks ill post there thanks mate,