我正在构建一个 iframe 应用程序,其中会提及 Facebook 主页的一些内容。我的应用程序将被添加到具有不同名称的多个页面。我需要的是这样的东西..
$page_name = "Bob's Toys";
Thank you for visiting the <?php echo $page_name; ?> page!
有没有办法做到这一点?
最佳答案
是的。解码 Facebook 发送到页面的 signed_request。
if (!empty($_REQUEST['signed_request'])) {
$signedRequest = $_REQUEST['signed_request'];
list($sig, $payload) = explode('.', $signedRequest, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
}
从那里,您可以获得页面的 ID。
array (size=4)
'algorithm' => string 'HMAC-SHA256' (length=11)
'issued_at' => int 1321635439
'page' =>
array (size=3)
'id' => string '19292868552' (length=15)
'liked' => boolean false
'admin' => boolean true
'user' =>
array (size=3)
'country' => string 'gb' (length=2)
'locale' => string 'en_US' (length=5)
'age' =>
array (size=1)
'min' => int 21
然后您可以使用图形 API 返回如下所示的页面对象:https://graph.facebook.com/19292868552
关于php - 有没有办法用 PHP 获取 Facebook 页面的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8185689/