How to clear Facebook Sharer cache? - facebook

We used the link:
http://www.facebook.com/sharer.php?u=[shared URL]
...to share a particular page. However, Facebook Sharer uses the cached version of the images and the title. Is there a way to quickly clear the Facebook cache or how long do we have to wait until the data gets updated?
I placed <link rel='image_src' href='[preview image]' /> in between the tags.

I found a solution to my problem. You could go to this site:
https://developers.facebook.com/tools/debug
...then put in the URL of the page you want to share, and click "debug". It will automatically extract all the info on your meta tags and also clear the cache.

Use api Is there an API to force Facebook to scrape a page again?
$furl = 'https://graph.facebook.com';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $furl );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POST, true );
$params = array(
'id' => '<update_url>',
'scrape' => true );
$data = http_build_query( $params );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_exec( $ch );
$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

Facebook treats each url as unique and caches the page based on that url, so if you want to share the latest url the simplest solution is to add a query string with the url being shared. In simple words just add ?v=1 at the end of the url. Any number can be used in place of 1.
Hat tip: Umair Jabbar

I thing these two links have a wide discussion on your problem related stuff. fb:ref clear cashes by calling
fbml.refreshRefUrl
like this
<tt>fbml.refreshRefUrl("http://www.mysite.com/someurl.php")
You can study the related stuff from here fb:ref. I hope it will work for you

The page to do this is at https://developers.facebook.com/tools/debug/ and has changed slightly since some of the other answers.
Paste your URL in there and hit "Debug". Then hit the "Fetch new scrape information" button under the URL text field and you should be all set. It'll pull the fresh meta tags from your page, but they'll still cache so keep in mind you'll need to do this whenever you change them. This is really critical if you are playing with the meta tags to get FB Shared URLs to format the way you want them to inside of facebook.

This answer is intended for developers.
Clearing the cache means that new shares of this webpage will show the new content which is provided in the OG tags. But only if the URL that you are working on has less than 50 interactions (likes + shares). It will also not affect old links to this webpage which have already been posted on Facebook. Only when sharing the URL on Facebook again will the way that Facebook shows the link be updated.
catandmouse's answer is correct but you can also make Facebook clear the OG (OpenGraph) cache by sending a post request to graph.facebook.com (works for both http and https as of the writing of this answer). You do not need an access token.
A post request to graph.facebook.com may look as follows:
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: graph.facebook.com
Content-Length: 63
Accept-Encoding: gzip
User-Agent: Mojolicious (Perl)
id=<url_encoded_url>&scrape=true
In Perl, you can use the following code where the library Mojo::UserAgent is used to send and receive HTTP requests:
sub _clear_og_cache_on_facebook {
my $fburl = "http://graph.facebook.com";
my $ua = Mojo::UserAgent->new;
my $clearurl = <the url you want Facebook to forget>;
my $post_body = {id => $clearurl, scrape => 'true'};
my $res = $ua->post($fburl => form => $post_body)->res;
my $code = $res->code;
unless ($code eq '200') {
Log->warn("Clearing cached OG data for $clearurl failed with code $code.");
}
}
}
Sending this post request through the terminal can be done with the following command:
curl -F id="<URL>" -F scrape=true graph.facebook.com

Append a ?v=random_string to the url.
If you are using this idea with Facebook share, make sure that the og:url param in the response
matches the url you are sharing. This will work with google plus too.
For Facebook, you can also force recrawl by making a post request to https://graph.facebook.com
{id: url,
scrape: true}

I just posted a simple solution that takes 5 seconds here on a related post here - Facebook debugger: Clear whole site cache
short answer... change your permalinks on a worpdress site in the permalinks settings to a custom one. I just added an underscore.
/_%postname%/
then facebook scrapes them all as new urls, new posts.

if you are using wordpress with a cache plugin, make sure you clear all your caches. Also make sure the image you are using has the recommended facebook size: 1200(w) x 630(h) or 600 x 315.

If you used managed wordpress or caching plugins, you have to CLEAR YOUR CACHE before the facebook debugger tool can fetch new info!
I've been pulling my hair out for weeks figuring out why changes I made wouldn't show up in facebook debugger for 24 hours!!!! The fix is I have to go into my wordpress dashboard, click the godaddy icon on the top, and click "flush cache." I think many managed wordpress hosters have a cache to figure out how to clear it and you'll be golden.

Related

Scrape new page using opengraph and curl

I am developing a website in which i have created a blog, on that blog people can comment via their facebook. Now i noticed that whenever i create a new blog, the comments plugin shows a warning "url is unreachable".
I already figured out that the way to get rid of this warning is to scrape the new blog.
if i use following query on the commandline:
curl -F "id=http://www.maartenvangenechten.be/blog/post/13/" -F "scrape=true" -k https://graph.facebook.com
the warning disappears, but on the long run this isn't the best way. Also all the data i putted in metatags are outputted, telling me that the page is succesfully scraped
so i tried using php/libcurl for this:
$params = array(
"id"=>$url,
"scrape"=>"true");
$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);
curl_close($ch);
echo $result;
now this only outputs:
{"id":"214022612077699","url":"http:\/\/www.maartenvangenechten.be\/blog\/post\/13\/"}
and not
{"url":"http:\/\/www.maartenvangenechten.be\/","type":"website","title":"Maartens Homepage","image":[{"url":"http:\/\/www.maartenvangenechten.be\/images\/general\/logo_enlighten.gif"}],"description":"Hier kan je alles vinden over mijn huidige projecten. Bekijk ook zeker de blog, waar ik de verschillende uitdagingen die ik tegenkom zal toelichten","site_name":"VangenechtenDESIGNs","admins":[{"id":"591822147","name":"Maarten Van Genechten","url":"http:\/\/www.facebook.com\/exquisitje"}],"updated_time":"2013-02-22T02:27:18+0000","id":"492686967461912","application":{"id":"482576148470885","name":"MVGPortfolio","url":"http:\/\/www.facebook.com\/apps\/application.php?id=482576148470885"}}
as i would expect
Can't seem to find why
Ok, solved it, after searching the web for a couple of hours...
I tried the function on different browsers, and Opera, Firefox, and even IE returned the expected result, only Chrome gave the problem...
Cleared the cache, history, and about everything else stored via Chrome, and the problem was gone.

How to force Facebook to use https into a tab url

My server use only https with an htaccess redirect at root level, when my tab app is called from a FB page if the user use an http connection I lost the signed request.
Everyone knows a solution?
How to force Facebook to use https when call a tab?
thanks
luc
How to force Facebook to use https when call a tab?
In theory, HTTP status codes 307 (Temporary Redirect) and 308 (Permanent Redirect) should be used for this, since they require the method to stay the same, so the client would have to fetch the resource that’s been redirected to using POST with the same data again.
However, I have no experience how well this works with the browsers that are out there.
Probably better to “redirect” client-side, using JavaScript. Of course, that requires a resource that is available using HTTP only, and is not redirected server-side to it’s HTTPS counterpart.
In the future, this “problem” will go away on it’s own, I assume – since Facebook announced end of last year that they will move all users to HTTPS; so I think some time from now we won’t be required to give a HTTP URL for canvas/page tab apps any more, and use just one HTTPS version.
I resolved in this way:
In the FBapp manager I used as http url a page created on a different server that accept http.
In this page I used the following code .
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$fql_query_url = "https://graph.facebook.com"
."/$page_id?fields=link"
."";
try {
$fql_query_result = #file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
} catch(Exception $o){ }
$pageinfo = $fql_query_obj[link];
$pageinfo = str_replace("http://","https://",$pageinfo);
$tabpage = "$pageinfo"."?sk=app_$appId";
echo "
<!-- force tab iframe -->
<script type=\"text/javascript\">
top.location.replace('$tabpage');
</script>
";
?>
that's all

How do I force the Facebook Like Button to re-scrape my page?

I created a like button on a page (http://www.usna.edu/BillAF/game.php) that sends the URL/data for it's parent page. Unfortunately, when I first put it in, an older version of the page was at the location of the parent page that did not have the open graph meta-tags on it.
So when someone "likes" the page, it sends the wrong title and a "garbage" image of half of the letter "e" on a white and gray square.
I checked: http://developers.facebook.com/tools/debug and it has the updated info. I also tried changing the associated AP ID to a new one, and neither seems to have refreshed what it sends when I "like" it. I also tried adding index.php to the end of the URL it is supposed to be posting (http://www.usna.edu/BillAF) but to no avail.
Is there anything I can do to force it to re-scrape the page? If not, does anyone know how long it will take for facebook to re-scrape it on their own?
A good way to clear the facebook cached image and text is by running the tool Debugger:
http://developers.facebook.com/tools/debug
By putting the url that you are sharing there, it will refresh facebook cache from your website.
Facebook has an API for re-scraping page data, I use the following function:
function purgeFacebookCache($url, $debug=false) {
// Set the variables for Facebook
$fields = array(
'id' => urlencode($url),
'scrape' => true
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
// Connect
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://graph.facebook.com');
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
// Debug
if ($debug) {
var_dump($result);
}
}

How to refresh Facebook Like Image (clear cache) [duplicate]

We used the link:
http://www.facebook.com/sharer.php?u=[shared URL]
...to share a particular page. However, Facebook Sharer uses the cached version of the images and the title. Is there a way to quickly clear the Facebook cache or how long do we have to wait until the data gets updated?
I placed <link rel='image_src' href='[preview image]' /> in between the tags.
I found a solution to my problem. You could go to this site:
https://developers.facebook.com/tools/debug
...then put in the URL of the page you want to share, and click "debug". It will automatically extract all the info on your meta tags and also clear the cache.
Use api Is there an API to force Facebook to scrape a page again?
$furl = 'https://graph.facebook.com';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $furl );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POST, true );
$params = array(
'id' => '<update_url>',
'scrape' => true );
$data = http_build_query( $params );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_exec( $ch );
$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
Facebook treats each url as unique and caches the page based on that url, so if you want to share the latest url the simplest solution is to add a query string with the url being shared. In simple words just add ?v=1 at the end of the url. Any number can be used in place of 1.
Hat tip: Umair Jabbar
I thing these two links have a wide discussion on your problem related stuff. fb:ref clear cashes by calling
fbml.refreshRefUrl
like this
<tt>fbml.refreshRefUrl("http://www.mysite.com/someurl.php")
You can study the related stuff from here fb:ref. I hope it will work for you
The page to do this is at https://developers.facebook.com/tools/debug/ and has changed slightly since some of the other answers.
Paste your URL in there and hit "Debug". Then hit the "Fetch new scrape information" button under the URL text field and you should be all set. It'll pull the fresh meta tags from your page, but they'll still cache so keep in mind you'll need to do this whenever you change them. This is really critical if you are playing with the meta tags to get FB Shared URLs to format the way you want them to inside of facebook.
This answer is intended for developers.
Clearing the cache means that new shares of this webpage will show the new content which is provided in the OG tags. But only if the URL that you are working on has less than 50 interactions (likes + shares). It will also not affect old links to this webpage which have already been posted on Facebook. Only when sharing the URL on Facebook again will the way that Facebook shows the link be updated.
catandmouse's answer is correct but you can also make Facebook clear the OG (OpenGraph) cache by sending a post request to graph.facebook.com (works for both http and https as of the writing of this answer). You do not need an access token.
A post request to graph.facebook.com may look as follows:
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: graph.facebook.com
Content-Length: 63
Accept-Encoding: gzip
User-Agent: Mojolicious (Perl)
id=<url_encoded_url>&scrape=true
In Perl, you can use the following code where the library Mojo::UserAgent is used to send and receive HTTP requests:
sub _clear_og_cache_on_facebook {
my $fburl = "http://graph.facebook.com";
my $ua = Mojo::UserAgent->new;
my $clearurl = <the url you want Facebook to forget>;
my $post_body = {id => $clearurl, scrape => 'true'};
my $res = $ua->post($fburl => form => $post_body)->res;
my $code = $res->code;
unless ($code eq '200') {
Log->warn("Clearing cached OG data for $clearurl failed with code $code.");
}
}
}
Sending this post request through the terminal can be done with the following command:
curl -F id="<URL>" -F scrape=true graph.facebook.com
Append a ?v=random_string to the url.
If you are using this idea with Facebook share, make sure that the og:url param in the response
matches the url you are sharing. This will work with google plus too.
For Facebook, you can also force recrawl by making a post request to https://graph.facebook.com
{id: url,
scrape: true}
I just posted a simple solution that takes 5 seconds here on a related post here - Facebook debugger: Clear whole site cache
short answer... change your permalinks on a worpdress site in the permalinks settings to a custom one. I just added an underscore.
/_%postname%/
then facebook scrapes them all as new urls, new posts.
if you are using wordpress with a cache plugin, make sure you clear all your caches. Also make sure the image you are using has the recommended facebook size: 1200(w) x 630(h) or 600 x 315.
If you used managed wordpress or caching plugins, you have to CLEAR YOUR CACHE before the facebook debugger tool can fetch new info!
I've been pulling my hair out for weeks figuring out why changes I made wouldn't show up in facebook debugger for 24 hours!!!! The fix is I have to go into my wordpress dashboard, click the godaddy icon on the top, and click "flush cache." I think many managed wordpress hosters have a cache to figure out how to clear it and you'll be golden.

Facebook iFrame app links send outside

any FB experts here? After reading about 15 thread on FB forums I don'T know where to go next =(
We have an iFrame FB app: http://apps.facebook.com/myapp
all links used in app are like: href="http://www.mysite.com/index.php?parm=value ..."
now when I click on any link, I am out of facebook and land on our server.
Don't really know how to solve this! using links with facebook server ins't an option.
Thanks guys for some hints!
This is because Facebook loses all of the authentication variables and is unable to determine that the concurrent requests belong to the same session, which results in "breaking out" of the iframe and ending up on your own server pages instead of within Facebook.
Anytime a page is served through Facebook, the request received at your server will include a number of GET variables sent by Facebook, these variables are collectively known as the "Facebook Authentication Signature" which proves to your server that the request actually is valid and originated from Facebook; likewise, when your server sends the response, the inclusion of these variables proves to Facebook (by a combination of the session_key, api_key, and sig digest) that your server is the application it claims to be.
In order to persist the session within your iframe app without breaking out to your server, you must include these parameters on each link's query string. Here is a simple function that will produce the query string for you, so you simply need to append the result of this function to each link URL in your application:
function fb_sig_urlQueryString() {
$query = '';
foreach ($_GET as $k => $v) {
if (strpos($k, 'fb_sig') === 0) {
if ($i++ > 1) $query .= '&';
$query .= $k.'='.$v;
}
}
return $query;
}
Do you mean clicking a link in the iframe goes to your site intead? If you do you could try setting the "target" attribute of the html anchor to "_self" which should open the link in the iFrame.
I was having this problem. After appending all the FB querystring parameters from the initial IFrame to each of the urls in my links, they started opening in the right windows.
See here for an example http://www.keywordintellect.com/facebook-development/facebook-iframe-authentication-across-pages-ajax-requests/