-
-
Save FrostyX/81d58222d1e835e24013 to your computer and use it in GitHub Desktop.
<?php | |
class FacebookDebugger | |
{ | |
/* | |
* https://developers.facebook.com/docs/opengraph/using-objects | |
* | |
* Updating Objects | |
* | |
* When an action is published, or a Like button pointing to the object clicked, | |
* Facebook will 'scrape' the HTML page of the object and read the meta tags. | |
* The object scrape also occurs when: | |
* | |
* - Every 7 days after the first scrape | |
* | |
* - The object URL is input in the Object Debugger | |
* http://developers.facebook.com/tools/debug | |
* | |
* - When an app triggers a scrape using an API endpoint | |
* This Graph API endpoint is simply a call to: | |
* | |
* POST /?id={object-instance-id or object-url}&scrape=true | |
*/ | |
public function reload($url) | |
{ | |
$graph = 'https://graph.facebook.com/'; | |
$post = 'id='.urlencode($url).'&scrape=true'; | |
return $this->send_post($graph, $post); | |
} | |
private function send_post($url, $post) | |
{ | |
$r = curl_init(); | |
curl_setopt($r, CURLOPT_URL, $url); | |
curl_setopt($r, CURLOPT_POST, 1); | |
curl_setopt($r, CURLOPT_POSTFIELDS, $post); | |
curl_setopt($r, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($r, CURLOPT_CONNECTTIMEOUT, 5); | |
$data = curl_exec($r); | |
curl_close($r); | |
return $data; | |
} | |
} | |
?> |
<?php | |
$fb = new FacebookDebugger(); | |
$fb->reload('http://example.com/'); | |
$fb->reload('http://example.com/foo'); | |
$fb->reload('http://example.com/bar'); | |
?> |
This works really really well and solved our problem with fb caching images.
Thank you so much!
Thank you guys for all the positive feedback!
can confirm this still works in 2020, here a python implementation extending the Facebook Graph SDK
class GraphAPIExt(GraphAPI):
def scrape_url(self, url, **kwargs):
assert url, "object URL is required"
args = {
"id": url,
"scrape": True
}
args.update(kwargs)
return self.request("/", method="POST", args=args)
I wrote that code in high school nearly ten years ago (I published it later) and I would never guess that it would be still useful even today.
Thank all of you guys.
Must have a valid access token or a valid url_hmac
can confirm this still works in 2020, here a python implementation extending the Facebook Graph SDK
class GraphAPIExt(GraphAPI): def scrape_url(self, url, **kwargs): assert url, "object URL is required" args = { "id": url, "scrape": True } args.update(kwargs) return self.request("/", method="POST", args=args)
does this update the image
I've tried another simple approach. get the response but it does not seem to update anything
python code:
res = requests.post(f'{host}/?id={uri}&scrape=true&access_token={token}')
yes, this is what we are using right now in our production environment
Hey, I had different cat images and i am changing the og:image when page loads.
When i inspect the image is changing... but when i share or type my url... i am getting same preview (image)...
How to Fetch new scrape information when someone types or shares my url ?