Facebook application - get signed_request with JavaScript

user1067939 picture user1067939 · Nov 28, 2011 · Viewed 9.9k times · Source

I have a FaceBook application.

Is there any way to get signed_request with JavaScript?

With PHP it looks like this: $_REQUEST['signed_request'], but I can't use php.

Answer

Shaun Baker picture Shaun Baker · Nov 28, 2011

From the FB JavaScript SDK, you can use FB.getLoginStatus to retrieve the signed_request.

That is if the the user is logged into your app/website.

If not you can call the FB.login method.

Ref: http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

FOLLOWING ON TO YOUR COMMENT:

Hi,

I think you should try to log the response to your console.

The response.status should equal 'connected' if the user is logged. It will always return true, as a value will be returned in this response param.

The log will look like so

{
    status: 'connected',
    authResponse: {
        accessToken: '...',
        expiresIn:'...',
        signedRequest:'...',
        userID:'...'
    }
}

To test what is being return try this:

if(response.status == 'connected'){
   // user is logged and signed_request is accessible
   // with response.authResponse.signedRequest
}else{
   // user not logged in, request them to login
      FB.login(function(response){ ... });
}