問題描述
事實:我運行一個簡單的網站,其中包含文章、通過抓取第三方網站/博客等動態獲取的文章(新文章每半小時左右到達我的網站)、文章我想在我的 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/') );
這篇關于PHP &Facebook: facebook-debug a URL using CURL and Facebook debugger的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!