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
I am working on a PHP-based web app that's to be used internally by my agency's 3 team members, to read campaign and ads data.
Ideally, for the sake of security, the tool would never have the ability to edit ads.
It's a comparatively simple tool, I think. So I opted for cURL requests rather than using the PHP Business SDK.
The App is in 'In Development' mode, and it's being access by a System User in Business Manager whose token permissions are:
read_insights
ads_read
pages_read_engagement
The System User has been given access to the following Assets:
The Ad Account. Permissions granted: View Performance
The Page. Permissions granted: View Page Performance
With those settings in place, the application is able to pull almost everything needed to view the info we require for our campaigns/ad sets/ads. I'm quite proud of it. But there's only one problem. I can't seem to get the destination URL for any ads through any API requests.
From what I understand, I need to query an ad's AdCreative.
With php cURL requests like this:
$access_token = "REDACTED";
$app_secret = "REDACTED";
$appsecret_proof = hash_hmac('sha256', $access_token, $app_secret);
$handle = curl_init();
$url = "https://graph.facebook.com/v7.0/23845023771530707?fields=object_story_spec,thumbnail_url,link_url,call_to_action_type&access_token=$access_token&appsecret_proof=$appsecret_proof";
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($handle);
curl_close($handle);
$result = json_decode($output,true);
echo "<pre>";print_r($result);echo "</pre>";
I get the following return:
Array
(
[object_story_spec] => Array
(
[page_id] => 104422504276761
)
[thumbnail_url] => https://external.xx.fbcdn.net/safe_image.php?d=AQCP_C2YI....Shortened here for clarity of this post
[id] => 23845023771530707
)
In short, only about half of the fields seem to populate. I really need to get the final destination URL of an ad. I do not get the link_url or call_to_action_type fields that I requested. :(
So, I'm wondering things like...
Am I going about this wrong? Is AdCreative the wrong way to query this info?
Am I somehow still lacking permissions?
Am I unable to get these fields because the App in still 'In Development'? Do I need to submit the App for Review?
Sorry there are several questions here rolled into one post.
The field object_story_spec in the creative object is only present if the ad created a new page-post on publish. It won't be present if the ad was created referencing an existing page-post.
Fortunately, the reference to the created/referenced page-post effective_object_story_id should exist on every ad-creative.
You can query the page-post via /{effective_object_story_id}?fields=... to find the data that would have otherwise existed in object_story_spec.
ad-creative: https://developers.facebook.com/docs/marketing-api/reference/ad-creative
page-post: https://developers.facebook.com/docs/graph-api/reference/page-post
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.
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);
}
}
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.
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/