问题
When I create a new web page with a Like button and access the page for the first time, the button doesn't show the og:title or og:description data, or the og:image that I've specified. I have to scrape the page manually first by running it through the Facebook debugger at https://developers.facebook.com/tools/debug.
My understanding is that Facebook scrapes the page every 24 hours automatically and if you want changes to show up sooner you have to scrape it yourself by running it through the debugger. But doesn't Facebook scrape the page once the first time you call the Like button on it, so I shouldn't have to scrape it the first time?
I should mention that the button code is not generated fresh by calling the Facebook button page at
https://developers.facebook.com/docs/plugins/like-button
Instead, the web page that gets the Like button is being generated by a site builder that I developed. When the user selects a Like button icon to put on the page, code from a previously generated button is patched to contain the new site name, etc.
Also, it's an XFMBL button, if that matters.
The best solution I could hope for, I guess, would be a way to call the Facebook debugger programatically from PHP with the URL to scrape in the query string, and the debugger would just do it without opening up any kind of a user dialog.
Thanks for any ideas.
回答1:
You can use this code to send it to the debbugger when you generate the like button:
$curlUrl = 'https://developers.facebook.com/tools/debug/og/object?q=' .
urlencode(your like link);
$access_token = FACEBOOK_APP_ID | FACEBOOK_APP_SECRET;
$params = array(
'id' => $curlUrl,
'scrape' => 'true',
'access_token' => $access_token
);
$ch = curl_init('https://graph.facebook.com');
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params
));
$result = curl_exec($ch);
来源:https://stackoverflow.com/questions/21415566/why-doesnt-like-button-work-immediately