根据请求将 FBML 切换到 iFrame pageID?

发布于 2024-12-02 02:08:36 字数 1236 浏览 2 评论 0原文

我们使用 FBML 开发了一个 facebook 应用程序作为选项卡应用程序。现在 Facebook 已弃用 fbml,我们正在将应用程序转换为 iframe。为此,用户可以创建一个 FB 页面并将应用程序添加到他们的 Facebook 页面。我们正在获取用户的 Facebook 页面 ID 并使用该页面 ID 签入数据库并显示该特定用户的数据。在 FBML 选项卡应用程序中,我们以请求的形式获取 facebook 页面 id ($REQUEST['page_id'])。这似乎不再起作用了。

  1. 当我们将应用程序转换为 IFRAME 选项卡应用程序时,FB 不提供页面 ID。我们没有使用 GRAPH API,并且在查看应用程序之前有任何身份验证。我从论坛上读到 Facebook 签署了请求,我们将获取页面 ID 并使用以下代码,但没有获取任何数据。

    $sgrequest = $_REQUEST['signed_request'];
    $requestVal = parse_signed_request($sgrequest,$secret);
    print_r($requestVal);
    $_REQUEST['signed_request']['app_data']
    
    函数 parse_signed_request($signed_request, $secret) {
    列表($encoded_sig,$payload)=爆炸('。',$signed_request,2);
    // 解码数据
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);
    
     if (strtoupper($data['算法']) !== 'HMAC-SHA256') {
       error_log('未知算法。需要 HMAC-SHA256');
       返回空值;
     }
    
     // 检查信号
     $expected_sig = hash_hmac('vctly987', $payload, $secret, $raw = true);
     if ($sig !== $expected_sig) {
       error_log('错误的 JSON 签名!');
       返回空值;
     }
    
     返回$数据;
    

    }

    函数base64_url_decode($input) { 返回base64_decode(strtr($input, '-_', '+/')); }

  2. 是否有其他方法可以通过 javascript 或任何其他方法获取粉丝页面的页面 id?

We developed a facebook application as tab application using FBML. Now Facebook had deprecated the fbml and we are converting our application to iframe. For this the user can create a FB page and add the application to their facebook page. We are taking the user's facebook page id and check in the DB with this page id and showing the data for that particular user. In the FBML tab application we are getting the facebook page id as a request($REQUEST['page_id']). This seems to no longer work.

  1. When we convert the application to IFRAME tab application, FB is not providing the page id. We are not using GRAPH API and there is any authentication before viewing the application. I had read from a forum that facebook signed request, we will get the page id and used the following code and not getting any data.

    $sgrequest = $_REQUEST['signed_request'];
    $requestVal = parse_signed_request($sgrequest,$secret);
    print_r($requestVal);
    $_REQUEST['signed_request']['app_data']
    
    function parse_signed_request($signed_request, $secret) {
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    // decode the data
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);
    
     if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
       error_log('Unknown algorithm. Expected HMAC-SHA256');
       return null;
     }
    
     // check sig
     $expected_sig = hash_hmac('vctly987', $payload, $secret, $raw = true);
     if ($sig !== $expected_sig) {
       error_log('Bad Signed JSON signature!');
       return null;
     }
    
     return $data;
    

    }

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

  2. Is there any other way to get the page id of the fan page through javascript or any other method?

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

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

发布评论

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

评论(2

尤怨 2024-12-09 02:08:36

您是否尝试在解析签名请求后打印 $requestVal[page][id] ?

根据 文档,签名的请求包含一个名为“page”的数组,其中包含关键“id”。它存储页面 ID 号的值。

have you tried printing out $requestVal[page][id] after parsing the signed request?

according to the documentation, the signed request contains an array called 'page' that contains the key 'id'. This stores the value of the page's id number.

深海少女心 2024-12-09 02:08:36

您能否确保在您的应用程序中启用 Canvas 的迁移设置signed_request https://developers.facebook.com/apps /

应用程序设置->先进的

Can you make sure you enable the migration setting signed_request for Canvas in your App https://developers.facebook.com/apps/.

App Settings -> Advanced

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文