Search code examples
phphtmlfacebookfacebook-php-sdk

Facebook Share Dialog Strips Anchor Tags


I've been doing some research and I have yet to find any information that is relevant to what I'm looking for. I've included some links to questions I've already found when they're relevant.

I made a page in WordPress (though the CMS isn't necissarily relevant), and one page has a series of comments. Before each comment, I created an anchor tag, so that if you go to the URL "http://website.com/#10", you'll be brought to the tenth comment. The URL and anchors work fine.

I am now trying to integrate Facebook Share functionality into the site. Specifically, I want to be able to share the URL "http://website.com/#10", with the #10 included, such that a user will be able to share a specific comment on social media and not just the entire comments page.

Following the Facebook Share Dialog example, located here, I crafted a URL that looks like this:

https://www.facebook.com/dialog/share?
    app_id=XXXXXXXXXXXXXX
    &display=popup
    &href=http%3A%2F%2Fwebsite.com%2F%2310
    &redirect_uri=XXXXXXXXXXXXXX

With all of the X's filled in with valid information. Note that the "href" parameter is "http%3A%2F%2Fwebsite.com%2F%2310", which is an encoded version of "http://website.com/#10". The "#" symbol is encoded as "%23".

This URL works relatively well for sharing. When I click on it, I'm brought to Facebook, which gives me the same dialog box they show on the Share Dialog developers page. However, after clicking on "Post to Facebook", I find that the actual URL that gets shared is, in fact, "http://website.com/?fb_action_ids=XXXXX&fb_action_types=og.shares". No "#10" anywhere in the URL.

Here's some information on the research I've done, to show that this is a new question (and to remove any repeated answers).

  • This question asks something quite similar to what I'm asking, and the only answer mentions a way to use Javascript to change all "#" symbols to "%23". However, I have already encoded my URL to do this, so the answer isn't relevant.
  • This question asks what I believe is a similar question, and the accepted answer basically says that the Share button is deprecated and continues by answering about the Like button. However, while the Share functionality may have once been deprecated, there is a fully working version on developers.facebook.com which I have already linked to. I would like to use this version, but with the ability to share links that include anchor tags.

Does anyone have any advice for how to proceed?


Solution

  • Using dialog does not seems to allow the URL to have #10, as you need.

    Instead you may use, for exemple: https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.terra.com.br%2F%23dia-13&display=popup&ref=plugin;

    What can be done is to open a window by javascript, using this URL, where u refers to URL.

    So far, there isn't a documentation that describes what parameters can be used with the URL. What is known is that images, title and description may be declared by <meta> tags using og:image, for example, to ensure some default content.

    As stated here: http://okaypl.us/blog/facebook-share-dialog-longer-accepts-custom-parameters/

    Some old parameters that probably are not working anymore are found in similar questions like: how to pass parameter like title,summary and image in facebook sharer url.