从页面选项卡URL检索参数 [英] Retrieve Parameter From Page Tab URL

查看:94
本文介绍了从页面选项卡URL检索参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有URL的Facebook选项卡应用程序。我想传递URL一些GET参数。通常这是我如何获得用户数据的签名请求:

  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'];
}

我想知道如何从url获取GET参数。网址看起来像:


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




我想要获取用户的值。



任何想法?

解决方案

您需要使用 app_data 参数。 Facebook会读取此参数并将其传递给您的应用程序:


此外,您的应用程序还将收到一个名为
app_data 作为 signed_request 的一部分,如果app_data参数在
中设置为原始查询字符串您的标签页加载的URL。它可以
看起来像这样:
https://www.facebook.com/YourPage?v=app_1234567890&app_data=any_string_here
如果您控制
链接的生成,您可以使用它自定义您呈现的内容。


在旁注中,您可以使用PHP-SDK来获取这样的签名请求:

  $ signed_request = $ facebook - > getSignedRequest(); 

更多这里: https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L489



此外,您还需要检查您是否在调用 / me 之前确实有一个有效的用户会话,我建议您可以查看PHP-SDK 示例


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?

解决方案

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.

这篇关于从页面选项卡URL检索参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆