Facebook like button adds query strin to the url - facebook

i am implementing the facebook like button, and specified for it the url to like,
when i click on the LIKE button, in facebook i saw the correct page the liked, but when i click on the link there
the link is what is specified in the code with some odd facebook querystring appended.
for exmpl:
the page that i like is
http://www.mydomain.com/path/to/the/page
when i clicked on the liked link in facebook, the url is:
http://www.mydomain.com/path/to/the/page?fb_action_ids=#####&fb_action_types=og.likes&fb_source=timeline_og&action_object_map={"###"%###}&action_type_map={"###"%3A"og.likes"}&action_ref_map=[]
and the page is not loaded correctly, is this is a facebook fault?

Use the xfbml or html5 version of social plugin and include in your metatag this
<meta property="og:url" content="...." />

Facebook adds various parameters to the URL so you can track where the visits are coming from etc. Its probably your page that doesn't work with these parameters, rather than facebook. Ideally, you page should just ignore these parameters if you don't need them.

I solved this problem by defining the URL in the fb:like button as well as in the og:url.
<fb:like href="http://www.yourwebsite.com/yourfullurl.html" send="true" layout="button_count" width="300" show_faces="false"></fb:like>
Now regardless of the parameters sent back from FB it seems to honor the count.

We can remove/strip the appended query string with the help of .htaccess file.
Place the code mentioned below in your .htaccess file:
RewriteCond %{QUERY_STRING} fb_action_ids=.*$
RewriteRule .* %{REQUEST_URI}? [R=301,L]
RewriteCond %{QUERY_STRING} fb_comment_id=.*$
RewriteRule .* %{REQUEST_URI}? [R=301,L]
This will do the trick :)

Related

How to redirect from image path

I'm using the Facebook Sharer snippet to allow users to share a specific post to their Facebook page. It's sharing a dynamic image passed into the FB Sharer (not the main url), so the image is www.site.com/path/to/image.jpg - when the user clicks on it from the actual Facebook post, as expected, it routes to that www.site.com/path/to/image.jpg.
My question is can I set up a redirect to ALWAYS send to the index.html page whenever the www.site.com/path is hit? I was thinking I could use javascript to redirect, but you can't fire javascript on a .jpg page. Is this an htaccess thing? If so, I have no idea how to go about that either. I am using Amazon S3 with Cloudfront.
Here is the FB Sharer -
window.open(http://www.facebook.com/sharer.php?u=${root}&t=${title})
This is working correctly, but looking for help on how to redirect any page that has a /path/ after www.site.com
This could work - you need to exclude the Facebook Crawler:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteRule ^path/to/([^.]+\.(jpe?g|gif|bmp|png))$ http://www.newurl.com [R=301,L,NC]
Sources:
htaccess redirect all images to different location and put image name in new url
Exempt Facebook Crawler from .htaccess redirect
I tested it here: https://htaccess.madewithlove.be/
Although, the ideal/usual way is NOT to share images directly, but URLs with the image as og:image tag.

Facebook crawler doesn't follow my rewrite rule

I have this in my HTACCESS:
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/1.1|Facebot|Twitterbot|Pinterest|Google.*snippet|/externalhit_uatext/)
RewriteRule /+(.*?)$ /api/getSocial.php?which=$1 [P]
And using the facebook debug tool with my website, I see that facebook is getting the url without being rewritten, which is very weird. This is the url:
http://lab.pre.rtve.es/carlos-v-ricardo/podcast/
¿Any ideas why the crawler is not following this redirect? ¿Has the name of the user agent changed for Facebook?
I can read in the official documentation that this should work.
Thank you very much.
In the https://developers.facebook.com/docs/sharing/webmasters/crawler it is also written the crawler can have the
facebookexternalhit/1.1
(+http://www.facebook.com/externalhit_uatext.php)
useragent, and you do not cover that.

facebook like button href vs og:url

I would like to clarify one thing.
I have a web page with a facebook like button.
In the head of the page, let's say www.exaple.com, I have
<meta property="og:url" content="https://www.example.com">
and no canonical link.
In the facebook like box I have
<div class="fb-like" data-href="http://www.example.com?strip=1" data-layout="box_count" data-share="false" data-action="like"></div>
The page www.example.com?strip=1 is slightly differentent from www.example.com.
I would expect that when I use the like button, in facebook I will find a post that points to www.example.com?strip=1, but this doesn't happen as I'm redirected to www.example.com.
Can you explain me why this happen? My guess is that Facebook goes to www.example.com?strip=1 and looks for og:url there. Since the og:url in www.example.com/strip=1 is www.example.com I am redirected to www.example.com.
Can you confirm that? Do you have any suggestion on how to keep the og:url as it is but make the like button redirect to www.example.com/strip=1?
For completeness, in the facebook debugger, feeding it with www.example.com/strip=1, it gives me www.example.com?strip=1 as fetched URL and www.example.com as canonical URL.

Like Button results showing up in "Other" interests

I have a Wordpress.org based website and I've set it up so that on each individual "post" page (single.php file) there's a Like button above the post so users can Like that individual post.
I was using iFrame and just switched over to XFBML but it didn't fix my problem. My code is:
<fb:like send="false" layout="button_count" width="80" show_faces="false"></fb:like>
The problem is when someone clicks "Like" it shows up in their "Other" Like activity on their Facebook page because I guess each post is considered it's own page. How can I make it so each post isn't considered a page and the Like results do not show up in someones "Other" activity?
My website is www.RockItPro.com and for example a single post url is http://www.rockitpro.com/2012/01/04/flyawayhook/
You could use a like button with a fixed url:
<fb:like href="http://example.com" send="true" width="450" show_faces="true"></fb:like>
That way you likes would end up summed to the page, on the other hand this defeats the purpose of liking those articles for the article as every user on facebook would get redirected to the fixed page.
To fix the Other-Category you will need to categorize your page. See https://developers.facebook.com/docs/opengraph/ for examples how to use so you can tag your ownership of the page and get admin permissions to it's facebook representation.

facebook "i like" question

I'm using facebook "i like" on my site. facebook uses the title tag of the page as what the person likes. is there a way to add a different title instead of defaulting to the title tag of the page?
You need to add OpenGraph property "title" inside the "head" tag of your site for that:
<meta property="og:title" content="Title for FB" />
You can then use linter to check if what Facebook thinks about your page is okay with you.
Not that I know of, but you can point it to a different URL using the href attribute. Your website could return your modified page title at that URL.
Source: API docs
like alessandro says. Its possible using the href atribute
<fb:like layout="button_count" class="like_button" href="your url stuf here"></fb:like>
I use php to put dinamically the href stuff, so using some RewriteRule on my htaccess and the tittle in the generated html , i can show what ever i whant, when they press the like button