Facebook 粉丝页面应用程序上的用户数据

发布于 2024-12-16 22:48:33 字数 266 浏览 0 评论 0原文

我创建了一个应用程序并将其连接到一个粉丝页面,以便在该页面中加载应用程序内容。

访问user_id和用户名只有在用户授权该应用程序的情况下才能访问。

如何在用户喜欢该页面的同时对应用程序进行授权?

我的意思是,当用户单击喜欢页面按钮时,还应该出现应用程序授权对话框。或者如果我错了请建议正确的方法。

--- 编辑 ----

我正在使用 php-sdk v3.1.1。

I have created a application and connected it to a fan page so that application content is loaded in that page.

To access user_id and name of user can only be accessed if user have authorized the application.

How application can be authorized at the same time as user have liked the page?

I mean that when user clicks on like page button application authorization dialog box should also appear. Or if i am wrong please suggest the right way.

--- EDIT ----

I am using php-sdk v3.1.1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靑春怀旧 2024-12-23 22:48:33

这是不可能的,类似页面的按钮没有以任何方式连接到您的应用程序。

您可以做的是解析传递给您的应用程序的signed_request参数,以检查用户是否喜欢该页面,如果喜欢,您可以检查是否可以获得用户对象,并在需要时将其重定向到授权。

如果您不需要用户 ID 或任何其他扩展功能(例如发布到墙上),而只想检查用户是否喜欢该页面,您可以只使用签名的请求,而无需考虑其余的授权。

您可以使用应用程序密钥和以下函数解码signed_request:

function parse_signed_request_outside($signed_request, $secret) {
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);

    // decode the data
    $sig = base64_url_decode_outside($encoded_sig);
    $data = json_decode(base64_url_decode_outside($payload), true);

    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
        error_log('Unknown algorithm. Expected HMAC-SHA256');
        return null;
    }

    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
        error_log('Bad Signed JSON signature!');
        return null;
    }

    return $data;
}

function base64_url_decode_outside($input) {
    return base64_decode(strtr($input, '-_', '+/'));
}

为了确定类似的情况,您需要执行以下操作:

$secret = "SECRET KEY";

$decodedSignedRequest = parse_signed_request_outside($_REQUEST['signed_request'], $secret);

if ($decodedSignedRequest['page']['liked'] == 1){
{
   // load content
}

This isn't possible, the page like button is not connected in any way to your application.

What you can do is parse the signed_request parameter which is passed to your application to check if the user has liked the page, if he did you can then check if you can get the user object and redirect him to authorization if needed.

If you don't need the user id or any other extended features (such as posting to the wall) and just want to check if a user has liked the page you can just use the signed request and forget about the rest of the authorization.

You can decode the signed_request using your application secret key and the following function:

function parse_signed_request_outside($signed_request, $secret) {
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);

    // decode the data
    $sig = base64_url_decode_outside($encoded_sig);
    $data = json_decode(base64_url_decode_outside($payload), true);

    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
        error_log('Unknown algorithm. Expected HMAC-SHA256');
        return null;
    }

    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
        error_log('Bad Signed JSON signature!');
        return null;
    }

    return $data;
}

function base64_url_decode_outside($input) {
    return base64_decode(strtr($input, '-_', '+/'));
}

In order to determine the like you need to do the following:

$secret = "SECRET KEY";

$decodedSignedRequest = parse_signed_request_outside($_REQUEST['signed_request'], $secret);

if ($decodedSignedRequest['page']['liked'] == 1){
{
   // load content
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文