PHP &Facebook: facebook-debug a URL using CURL and Facebook debugger
事实:我运行一个简单的网站,其中包含文章、通过抓取第三方网站/博客等动态获取的文章(新文章每半小时左右到达我的网站)、文章我想在我的 facebook 页面上发帖.每篇文章通常包括一张图片、一个标题和一些文字.
Facts: I run a simple website that contains articles, articles dynamically acquired by scraping third-party websites/blogs etc (new articles arrive to my website every half an hour or so), articles which I wish to post on my facebook page. Each article typically includes an image, a title and some text.
问题:我在 Facebook 上发布的大部分(几乎所有)文章都没有正确发布 - 缺少图片.
Problem: Most (almost all) of the articles that I post on Facebook are not posted correctly - their images are missing.
低效解决方案:使用 Facebook 的调试器(这个)我向它提交了一篇文章的 URL(来自我网站的 URL,而不是原始来源的 URL),然后 Facebook 扫描/抓取 URL 并正确提取所需的信息(图像、标题、文本等).执行此操作后,文章可以正确发布到 Facebook 上 - 不会丢失图片或任何内容.
Inefficient Solution: Using Facebook's debugger (this one) I submit an article's URL to it (URL from my website, not the original source's URL) and Facebook then scans/scrapes the URL and correctly extracts the needed information (image, title, text etc). After this action, the article can be posted on Facebook correctly - no missing images or anything.
目标:我所追求的是一种创建过程的方法,该过程将向 Facebook 的调试器提交 URL,从而迫使 Facebook 扫描/抓取 URL,以便随后可以正确发布.我相信我需要做的是创建一个包含 URL 的 HTML POST 请求并将其提交给 Facebook 的调试器.这是正确的方法吗?如果是,因为我以前没有使用 CURL 的经验,那么在 PHP 中使用 CURL 的正确方法是什么?
Goal: What I am after is a way to create a process which will submit a URL to Facebook's debugger, thus forcing Facebook to scan/scrape the URL so that it can then be posted correctly. I believe that what I need to do is to create an HTML POST request containing the URL and submit it to Facebook's debugger. Is this the correct way to go? And if yes, as I have no previous experience with CURL, what is the correct way to do it using CURL in PHP?
旁注:作为旁注,我应该提到我的文章使用的是短 URL,尽管我认为这不是问题的原因,因为即使在我使用规范的 URL.
Side Notes: As a side note, I should mention that I am using short URLs for my articles, although I do not think that this is the cause of the problem because the problem persists even when I use the canonical URLs.
此外,Open Graph 元标记设置正确(og:image、og:description 等).
Also, the Open Graph meta tags are correctly set (og:image, og:description, etc).
推荐答案
您可以使用带有 PHP-cURL
的 Facebook 图形 API 调试图形对象,方法是执行 POST
You can debug a graph object using Facebook graph API with PHP-cURL
, by doing a POST
to
https://graph.facebook.com/v1.0/?id={Object_URL}&scrape=1
为了更简单,我们可以将调试器包装在一个函数中:
to make thing easier, we can wrap our debugger within a function:
function facebookDebugger($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v1.0/?id='. urlencode($url). '&scrape=1');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$r = curl_exec($ch);
return $r;
}
虽然这会更新 &为传递的 URL
清除 Facebook 缓存,打印出每个键有点困难它的内容并同时避免错误,但是我建议使用 var_dump()
或 print_r()
或 PHP-ref
though this will update & clear Facebook cache for the passed URL
, it's a bit hard to print out each key & its content and avoid errors in the same time, however I recommended using var_dump()
or print_r()
OR PHP-ref
使用 PHP-ref
r( facebookDebugger('http://retrogramexplore.tumblr.com/') );
相关文章