Search code examples
facebookparameter-passingfacebook-authentication

Facebook authentication dialog - Passing data to the redirect_uri


I am encountering a problem with passing data between pages that require facebook access.

Here is a simple example:
Page 1 - has data ({str:"123"}) (but still didn't get the facebook access)
Then it redirects to facebook_authentication which redirects to the redirect_uri (page 2)
Page 2 - needs to get the data from page one, but it was interrupted by the facebook auth dialog.(page 2 needs the facebook access to submit the str data).

Is there any way I can pass the data from page one through the auth dialog to page 2?
Something like so: auth_url..parameters..?str=123 then i'll get it in page 2 like so $_GET['str'];


Solution

  • I wrote an app that was running in facebook once and had to deal with this too. I used something like this

    $sAppId = '12345567999455';
    
    $sFBUrl = 'http://www.facebook.com/pages/<name>/<id>?sk=app_<app_id>&app_data=key:val;key:val';
    
    $sDialogUrl = 'https://www.facebook.com/dialog/oauth?client_id=' . $sAppId . '&redirect_uri=' . urlencode($sFBUrl)
    
    echo "<script>top.location.href='" . $sDialogUrl . "'</script>";   
    

    And then parsed the data

    $aAppData = explode(';', $aSignedRequest['app_data']);
    

    Which brings us to a solution for your case

    https://www.facebook.com/dialog/oauth?client_id=app_id&redirect_uri=your_url?str=123
    

    In my last app I used a trick I explained here: SSO Website-Network with Facebook Login

    Regards