0

I'm a PHP developer and I have nice experience with Facebook PHP SDK, but this time I'm lost :(

My problem is the following: I'm developing a facebook page tab application with Laravel, a PHP framework. This is my code:

    //getting the Facebook class instance
    $facebook = IoC::resolve('facebook-sdk');

    if(!$facebook->getUser()){
        $pagetab_url = 'https://www.facebook.com/PAGEUSERNAME?sk=app_APPID';    

        $loginUrlParams = array(
               'scope' => 'publish_stream',
               'redirect_uri' => $pagetab_url
        );

        $loginUrl = $facebook->getLoginUrl($loginUrlParams);

        echo("<script> top.location.href='" . $loginUrl . "'</script>");
    }
    else{
        echo $facebook->getUser();
    }

This code generates an infinite loop, because $facebook->getUser() always returns zero. AppId and AppSecret are correct, infact, if I change 'redirect_uri' to any page of my app domain, it works (for example: 'redirect_uri' => 'https://www.mysite.com/fb_callback').

Additional details: the signed request is always null. Do you have any idea?

Many thanks!

EDIT This solved my problem Facebook iframe tab signed request always empty

Community
  • 1
  • 1
jbdotdev
  • 163
  • 1
  • 1
  • 7
  • This solved my problem http://stackoverflow.com/questions/5253830/facebook-iframe-tab-signed-request-always-empty – jbdotdev Jan 06 '13 at 12:12

1 Answers1

0

I think rather than injecting a script which reloads the page, you need to give the user a chance to log into your app and authorize it.

Am I missing something? (You'll never get a result from $facebook->getUser() call unless the user is logged in AND has authorized your app).

Lastly, is there any reason you don't use:

header('Location: '.$loginUrl) ?

Instead of injecting javascript?

Are you developing on more than one server? (Localhost and a test server perhaps?) Another possibility is that you are testing on two different domains (localhost vs stage.whatever.com, for example) and you need to give your app permission to work on both domains.

Basically, log errors, if any, from the getUser() call and see what that output is.

fideloper
  • 12,213
  • 1
  • 41
  • 38
  • Yes, I'm working on more than one server. I need to authorize my users only in one page of my page tab application, so when they visit that page, i try to obtain their fb profile information. If getUser returns 0, then I redirect them to $loginUrl and after the authorization process, I need facebook to redirect them to my page tab page (this step is easily implementable setting up app_data into signed_request, but signed_request is always null in my page tab app). – jbdotdev Jan 02 '13 at 23:52
  • Instead of redirecting them when you get no login information, you should give them the ability to login / authorize. This usually isn't a redirect, but rather a JS method or button which uses Facebook's SDK to create teh popup or new tab with the login information. Usually you have a view (your displayed page) that conditionally shows content based on if user is logged in or not - instead of redirecting. – fideloper Jan 05 '13 at 17:23