Retrieve Parameter From Page Tab URL

谁说胖子不能爱 提交于 2019-12-23 02:49:04

问题


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:


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.



来源:https://stackoverflow.com/questions/13919541/retrieve-parameter-from-page-tab-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!