Facebook Connect - Using both FBML and PHP Client

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2009-10-15T18:22:47Z Indexed on 2010/04/09 1:03 UTC
Read the original article Hit count: 364

Filed under:
|
|

I am doing my second Facebook connect site. On my first site, I used the facebook coonect FBML to sign a user in, then I could access other information via the PHP Client. With this site, using the same exact code, it doesn't seem to be working. I'd like someone to be able to sign in using the Facebook button:

<fb:login-button length="long" size="medium" onlogin="facebook_onlogin();"></fb:login-button>

After they have logged in, the facebook_onlogin() function makes some AJAX requests to a PHP page which attempts to use the Facebook PHP Client. Here's the code from that page:

	$facebook = new Facebook('xxxxx API KEY xxxxx', 'xxxxx SECRET KEY xxxxx');
	//$facebook->require_login(); ** I DONT WANT THIS LINE!!

	$userID = $facebook->api_client->users_getLoggedInUser();

	if($userID) {

		$user_details = $facebook->api_client->users_getInfo($userID, 'last_name, first_name'); 
		$firstName = $user_details[0]['first_name']; 
		$lastName = $user_details[0]['last_name']; 

		$this->view->userID = $userID;
		$this->view->firstName = $firstName;
		$this->view->lastName = $lastName;
	}

The problem is that the PHP Client thinks I don't have a session key, so the $userID never get set. If I override the $userID with my facebook ID (which I am logged in with) I get this error:

exception 'FacebookRestClientException' with message 'A session key is required for calling this method' in C:\wamp\www\mab\application\Facebook\facebookapi_php5_restlib.php:3003

If I uncomment the require_login(), it will get a session ID, but it redirects pages around a lot and breaks my AJAX calls. I am using the same code I successfully did this with on another site. Anyone have any ideas why the PHP client don't know about the session ID after a user has logged in with the connect button? Any ideas would be greatly appreciated. Thanks!

© Stack Overflow or respective owner

Related posts about facebook

Related posts about facebook-connect