Retrieve Parameter From Page Tab URL

2019-06-05 03:51发布

I have a facebook tab application that has an URL. I want to pass the URL some GET parameters. Normally this is how I do a signed request to get user data:

if ($signed_request = parsePageSignedRequest()) {   
    $config = array(
        'appId'  => $app_id,
        'secret' => $app_secret,
    );

    $facebook = new Facebook($config);


    $ret_obj = $facebook->api('/me', 'GET', array());

    $theemail = $ret_obj['email'];
    $thename = $ret_obj['name'];
    $theusername = $ret_obj['username'];
}

I was wondering how to get the GET parameter from the url. The url looks like:

https://www.facebook.com/pages/Msomepagey/23023424231927?sk=app_518726691484563&user=someuser

I want to get the value for user.

Any ideas?

1条回答
何必那么认真
2楼-- · 2019-06-05 04:15

You need to use the app_data parameter. Facebook would read this parameter and pass it to your app within the request:

In addition, your app will also receive a string parameter called app_data as part of signed_request if an app_data parameter was set in the original query string in the URL your tab is loaded on. It could look like this: "https://www.facebook.com/YourPage?v=app_1234567890&app_data=any_string_here". You can use that to customize the content you render if you control the generation of the link.

On a side note, you can use the PHP-SDK to also get the signed request like this:

$signed_request = $facebook->getSignedRequest();

More here: https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L489

Also you need to check if you actually have a valid user session before calling /me, I suggest you have a look at the PHP-SDK example.

查看更多
登录 后发表回答