如何找出哪个主页安装了我的 Facebook 应用程序/哪个页面正在加载我的应用程序

How can I find out what Page has installed my Facebook App / which page is loading my app(如何找出哪个主页安装了我的 Facebook 应用程序/哪个页面正在加载我的应用程序)
本文介绍了如何找出哪个主页安装了我的 Facebook 应用程序/哪个页面正在加载我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个画布应用程序 (http://apps.facebook.com/myapp),其他页面(企业等)可以将它添加到他们的页面.在我的应用中,我如何知道我是从哪个页面被调用的?

I have a canvas app (http://apps.facebook.com/myapp) and other pages (businesses, etc) can Add it to their page. Within my app, how can I know which page I'm being called from?

我使用的是 PHP-SDK

I'm using the PHP-SDK

推荐答案

如 Facebook 页面中所述标签教程:

当用户导航到 Facebook 时页面,他们会看到你的页面标签添加在下一个可用选项卡中位置.从广义上讲,页面选项卡是以完全相同的方式加载画布页面.当用户选择您的页面选项卡,您将收到signed_request 参数为 1附加参数,page.这参数包含一个 JSON 对象一个 id(当前的页面 id页面),管理员(如果用户是管理员页面),并喜欢(如果用户已喜欢该页面).和画布一样页面,您将不会收到所有您可以访问的用户信息应用程序在signed_request 中,直到用户授权您的应用程序.

When a user navigates to the Facebook Page, they will see your Page Tab added in the next available tab position. Broadly, a Page Tab is loaded in exactly the same way as a Canvas Page. When a user selects your Page Tab, you will received the signed_request parameter with one additional parameter, page. This parameter contains a JSON object with an id (the page id of the current page), admin (if the user is a admin of the page), and liked (if the user has liked the page). As with a Canvas Page, you will not receive all the user information accessible to your app in the signed_request until the user authorizes your app.

因此,捕获页面 ID 的一种方法是:

So one way to capture the page id would be:

<?php
// PATH TO FB-PHP-SDK
require '../../src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'APP_ID',
  'secret' => 'APP_SECRET',
  'cookie' => true,
));
$signed_request = $facebook->getSignedRequest();
if( $page = $signed_request['page'] ) {
    echo $page['id'];
}
?>

或者没有 PHP-SDK 的解决方案:

OR a solution without the PHP-SDK:

<?php
if(!empty($_REQUEST["signed_request"])) {
    $app_secret = "APP_SECRET";
    $data = parse_signed_request($_REQUEST["signed_request"], $app_secret);

    if (isset($data["page"])) {
        echo $data["page"]["id"];
    } else {
        echo "Not in a page";
    }
}

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('sha256', $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, '-_', '+/'));
}

这篇关于如何找出哪个主页安装了我的 Facebook 应用程序/哪个页面正在加载我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)