内容无粉丝到内容粉丝

发布于 2024-12-05 11:06:38 字数 224 浏览 6 评论 0原文

当用户单击“类似”按钮时(它直接使用新内容重新加载页面),我想更改页面的内容。

我可以做到这一点,但前提是我首先单击登录按钮以获取我的帐户的基本信息。我不想要求这一步。

我想要的一个例子是 https://www.facebook.com/Dior (选项卡 Dior VIII )。

I would like to change the content of my page, when the user clicks on a like button (it's directly reloading the page with the new content).

I can do that but only if I click on the log-in button first to get the basic information of my account. I don't want to require this step.

An exemple of what I want is at https://www.facebook.com/Dior (tab Dior VIII).

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

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

发布评论

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

评论(4

夜吻♂芭芘 2024-12-12 11:06:38

您将需要使用其中一个 SDK 来实现例程。 Facebook 将所谓的签名请求传递给所有画布应用程序以及在 iframe 中运行的此类应用程序。除此之外,它还包括当前用户是否喜欢该页面的信息。您需要检索信息并检查类似状态。

对于 PHP 来说,这将是这样的:

<?php
require(facebook.php); // include Facebook PHP SDK

$app_id = "your_app_id";
$app_secret = "your_app_secret";

$facebook = new Facebook(array(
  'appId' => $app_id,
  'secret' => $app_secret,
  'cookie' => true
));

$signed_request = $facebook->getSignedRequest();

if($signed_request = $this->parsePageSignedRequest()) {
  if($signed_request->page->liked) {
    // output fan content
  } else {
    // output non-fan content
  }
}

function parsePageSignedRequest() {
  if (isset($_REQUEST['signed_request'])) {
    $encoded_sig = null;
    $payload = null;
    list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
    $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
    return $data;
  }
  return false;
}
?>

You will needs to implement a routine using one of the SDKs. Facebook passes a so-called signed request to all canvas apps and such running in an iframe. Among other things it includes the information if the current user has liked the page. You need to retrieve the information and check the like status.

For PHP this would be something like this:

<?php
require(facebook.php); // include Facebook PHP SDK

$app_id = "your_app_id";
$app_secret = "your_app_secret";

$facebook = new Facebook(array(
  'appId' => $app_id,
  'secret' => $app_secret,
  'cookie' => true
));

$signed_request = $facebook->getSignedRequest();

if($signed_request = $this->parsePageSignedRequest()) {
  if($signed_request->page->liked) {
    // output fan content
  } else {
    // output non-fan content
  }
}

function parsePageSignedRequest() {
  if (isset($_REQUEST['signed_request'])) {
    $encoded_sig = null;
    $payload = null;
    list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
    $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
    return $data;
  }
  return false;
}
?>
记忆之渊 2024-12-12 11:06:38

有一个名为 getSignedRequest() 的方法。调用这个方法。此方法返回当前用户是否已经是 Facebook 页面的粉丝:

 $faceboook->getSignedRequest()

There is a method named getSignedRequest(). Call this method. This method returns if the current user is already a fan of the Facebook page or not:

 $faceboook->getSignedRequest()
撞了怀 2024-12-12 11:06:38

有一种更简单的方法可以使用 FB.Event.Subscribe 和边缘.创建。 JavaScript 代码位于 http:// Fivespot.me/like-reveal-simple.txt 中。

将此添加到您的着陆页,更改应用程序 ID 以及您想要在用户点赞 yoursite.com/afterlike.html 后重定向到的链接。

这是最简单、最有效的方法。

There is a much easier way of doing this using FB.Event.Subscribe and edge.create. The JavaScript code is in http://fivespot.me/like-reveal-simple.txt.

Add this to your landing page, change the application ID and the link you want to redirect to after the user likes where it says yoursite.com/afterlike.html.

This is the simplest most effective way of doing this.

空心空情空意 2024-12-12 11:06:38

页面收到签名的请求。对此进行解码以查明用户是否喜欢该页面。在 PHP 中:

<?php
    $signedRequestObject = parse_signed_request( $_POST["signed_request"],YOUR_APPLICATION_SECRET );

    if ($signedRequestObject["page"]){
        // This means this signed_request was generated on a page.
        if ($signedRequestObject["page"]["liked"]){
            // the page was liked
        }
    }

    //Used functions
    function parse_signed_request($signed_request, $secret) {
        list($encoded_sig, $payload) = explode('.', $signed_request, 2);
        $sig = $this->base64_url_decode($encoded_sig);
        $data = json_decode($this->base64_url_decode($payload), true);
        if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
            echo  'Unknown algorithm. Expected HMAC-SHA256 : ';
            return false;
        }
        $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
        if ($sig !== $expected_sig) {
            echo = 'Bad Signed JSON signature!';
            return false;
        }
        return $data;
    }

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

A page gets a signed request. Decode this to find out if the user has like the page. In PHP:

<?php
    $signedRequestObject = parse_signed_request( $_POST["signed_request"],YOUR_APPLICATION_SECRET );

    if ($signedRequestObject["page"]){
        // This means this signed_request was generated on a page.
        if ($signedRequestObject["page"]["liked"]){
            // the page was liked
        }
    }

    //Used functions
    function parse_signed_request($signed_request, $secret) {
        list($encoded_sig, $payload) = explode('.', $signed_request, 2);
        $sig = $this->base64_url_decode($encoded_sig);
        $data = json_decode($this->base64_url_decode($payload), true);
        if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
            echo  'Unknown algorithm. Expected HMAC-SHA256 : ';
            return false;
        }
        $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
        if ($sig !== $expected_sig) {
            echo = 'Bad Signed JSON signature!';
            return false;
        }
        return $data;
    }

    function base64_url_decode($input) {
        return base64_decode(strtr($input, '-_', '+/'));
    }
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文