首先,我对PHP很陌生,这是我第一个动态提供og标记的脚本。
Facebook调试页面似乎以某种方式获得了实际的php脚本,我认为这是不可能的。我目前对服务器端脚本的理解是,服务器只应该执行它们,而不应该显示它们。
Facebook似乎正在抓取我的php的初始化代码,而不是它的最后执行。除非我对php变量范围的理解是不正确的??我完全迷惑不解。
这是我的php逻辑。我将我的php变量$ogTitle和$ogImage初始化为一些默认字符串,然后根据我的php从url上指定的xml/media中刮取的内容更新相同的变量。
这是我的PHP
<?php
// Set the defaults...
$ogTitle=".Universal Media Thru Internet." ;
// the following inserted for debug to prove facebook is grabbing this value ??? instead of the final derived one.
$ogTitle="الباء WRONG TITLE MEANT TO BE THE DEFAULT IF PHP DOES NOT DYNAMICALLY DERIVE ONE" ;
$ogDescription="Mumti the Next Generation" ;
$ogUrl = "http://mumti.org" ;
// 20180413
if ($_GET['ms'] != '') {
$url = $_GET['ms'];
}
if ($_GET['mq'] != '') {
$url = $_GET['mq'];
}
if ($url != '') {
$xml=simplexml_load_file($url) or die("Error: Cannot access XML $url");
//
$Pic = $xml->SLIDE[0]->PIC;
$rcbmp_root = $xml->rcbmp_root;
// -) derive final path for image
if ($rcbmp_root == "")
$ogImage = dirname($url) . "/" . $Pic ;
else
$ogImage = dirname($url) . "/" . $rcbmp_root . $Pic ;
//
$ogTitle = $xml->SLIDE[0]->TXT;
// Cleanup the ogImage URL (aka path normalization)
$u = parse_url(strtolower($ogImage)); // returns the URL components in associative-array
$u['path'] = simplify($u['path']); // removes the .. notations from the path component
$ogImage = "{$u['scheme']}://{$u['host']}{$u['path']}"; // piece the components together into a URL
}
?>最简单的可视化验证器是以下链接(请将其粘贴在具有前缀视图源的Chrome或火狐浏览器的地址栏中:)
view-source:http://mumti.org/?mq=http://arabicrescue.com/AR/KIDS/WORDS/WORD/02/DARC01.XML它将正确的og:title和有效的og:image显示如下:
<meta lang="ar" property="og:title" content="البَاءُ" />
<meta property="og:image" content="http://arabicrescue.com/ar/arabic/letters.bmp/400_1/02.png">然而,使用完全相同的URL,Facebook调试页面坚持有错误
Facebook似乎正在获取我的php脚本的初始化值,而不是从"if ($url != '') {.“中获取任何东西。评价。
谢谢你对这件事的解释,因为我没能向facebook的错误报告解释我自己。*( https://developers.facebook.com/bugs/134977464017792/ )
发布于 2018-04-18 06:23:47
Facebook的修复方法是提供og:url作为实际的url,而不仅仅是网站的根url。否则,它将og:title显示为空(即。"")和og:图像和一些旧的图像(我的网站标识),它是爬虫机器人刮了一段时间。一些我无法真正理解和解释的事情。
无论如何,使用以下附加的php代码,facebook将正确返回标题和图像。

$ogImage = str_replace( " ", "%20", $ogImage );
// -) provide canonical url
// https://stackoverflow.com/questions/6768793/get-the-full-url-in-php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$ogUrl = str_replace( " ", "%20", strtolower($actual_link) );https://stackoverflow.com/questions/49890585
复制相似问题