Trouble inserting fbml into database

82 views Asked by At

Hi I am working with the facebook javascript sdk and I am having succcess using fbml to list the logged in users name like so...

<fb:name uid="loggedinuser" useyou="false"></fb:name>

What I would like to do next is assign this value to a php variable and insert it into my database. The problem I'm having is when I assign this value to a php variable like so...

$first_name = ('<fb:name uid="loggedinuser" useyou="false"></fb:name>');

What gets inserted into the data base is the literal expression of

<fb:name uid="loggedinuser" useyou="false"></fb:name>

instead of the users real name. Is there anyway to do this with the javascript sdk? Thanks!

2

There are 2 answers

1
Onel Sarmiento On

You need to get the variable of

<fb:name uid="loggedinuser" useyou="false"></fb:name>

before assigning it to

$first_name

0
phwd On

FBML data is generated on the fly, there isn't a way to transfer data over like this since FBML would load later after PHP code is completed. In addition

$first_name = ('<fb:name uid="loggedinuser" useyou="false"></fb:name>');

Would never evaluate to anything other than a string, this is just how PHP works. This one line of code cannot possibly determine the nature within based on a string.

The JavaScript SDK offers a way to do this already

FB.api('/me', function(response) {
  alert('Your name is ' + response.name);
});

Though this in JavaScript so you need to send the data in a AJAX call to your PHP application. It would be much easier if you just retrieved the session information after JS SDK login and let the PHP SDK take care of the rest.