Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an API to force Facebook to scrape a page again?

I'm aware you can force update a page's cache by entering the URL on Facebook's debugger tool while been logged in as admin for that app/page: https://developers.facebook.com/tools/debug

But what I need is a way to automatically call an API endpoint or something from our internal app whenever somebody from our Sales department updates the main image of one of our pages. It is not an option to ask thousands of sales people to login as an admin and manually update a page's cache whenever they update one of our item's description or image.

We can't afford to wait 24 hours for Facebook to update its cache because we're getting daily complaints from our clients whenever they don't see a change showing up as soon as we change it on our side.

like image 835
Felipe Brahm Avatar asked Aug 23 '12 21:08

Felipe Brahm


People also ask

How do I force Facebook to scrape my URL?

This is definitely the correct answer. POSTing /? id=<url>&scrape=true to graph.facebook.com will force a re-scrape of the og tags for hte url. One must remember that this must be a POST request, not a GET request, otherwise you just get the number of shares.

How do you fetch a new scrape on Facebook?

Look under “og:image” section of the content displayed. Chances are, your image is missing, there's no image there at all, or it's displaying an old image. In any of those cases, hit the blue “Fetch new scrape information”, and check again to see if the correct image is now displayed in the “og:image” section.

Does Facebook have an open API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.


2 Answers

Page metadata isn't the sort of thing that should change very often, but you can manually clear the cache by going to Facebook's Debug Tool and entering the URL you want to scrape

There's also an API for doing this, which works for any OG object:

curl -X POST \      -F "id={object-url OR object-id}" \      -F "scrape=true" \      -F "access_token={your access token}" \      "https://graph.facebook.com" 

An access_token is now required. This can be an app or page access_token; no user authentication is required.

like image 52
Igy Avatar answered Sep 16 '22 17:09

Igy


If you'd like to do this in PHP in a with-out waiting for a reply, the following function will do this:

//Provide a URL in $url to empty the OG cache function clear_open_graph_cache($url, $token) {   $vars = array('id' => $url, 'scrape' => 'true', 'access_token' => $token);   $body = http_build_query($vars);    $fp = fsockopen('ssl://graph.facebook.com', 443);   fwrite($fp, "POST / HTTP/1.1\r\n");   fwrite($fp, "Host: graph.facebook.com\r\n");   fwrite($fp, "Content-Type: application/x-www-form-urlencoded\r\n");   fwrite($fp, "Content-Length: ".strlen($body)."\r\n");   fwrite($fp, "Connection: close\r\n");   fwrite($fp, "\r\n");   fwrite($fp, $body);   fclose($fp); } 
like image 21
Shawn Conn Avatar answered Sep 17 '22 17:09

Shawn Conn