0

I'm currently writing a facebook app. In my app, the user is identified with the Javascript FB SDK:

    FB.init({
            appId  : appId,
            status : true, 
            cookie : true, 
            xfbml  : true, 
        });

  FB.ui({method: 'oauth'  
        ,client_id: appId  
        ,redirect_uri: 'some_URI'  
        ,scope: 'publish_stream'});` 

After the user loggs in, I can get the access token like this:

FB.getLoginStatus(function(response) {
    if (response.session) {
    alert(response.session.access_token);

My question is, if I could pass it back to the php code in order to use it?

Sharon Haim Pour
  • 5,974
  • 12
  • 39
  • 59

3 Answers3

0

you can send it via ajax request to your php script & use/operate with it as you want

genesis
  • 48,512
  • 18
  • 91
  • 118
0

Well, theoretically you could just do a ajax query and send the access token back to a php, e.g. http://www.mydomain.com/setfbtoken?token=

Correct me if I'm wrong, but the session should be attached to your url as a get parameter (at least it is in PHP), so you could just fetch it off the $_GET parameter.

Ben
  • 335
  • 2
  • 12
  • Thanks for the advice. I don't think that the $_GET['session'} is the same as the response.session. – Sharon Haim Pour Aug 02 '11 at 15:25
  • Well I have never used the javascript implementation so I can't tell for sure. It should still work using something like: var myRequest = new Request.HTML ({ url: 'data.php', data: {acccesstoken: response.session.access_token} }).send(); IF you are using mootools. – Ben Aug 02 '11 at 15:32
0

I think you can use this as in theory you should have the facebook cookie.

The information I posted here Facebook PHP SDK getSession() fails to get session. Cookie problem? might be useful and the functions listed there.

Community
  • 1
  • 1
TommyBs
  • 8,497
  • 3
  • 26
  • 58