Facebook Sharer - Title and summary Customization

╄→гoц情女王★ 提交于 2019-11-30 08:56:27
AlvaroAV

Facebook Sharer without Open Graph meta tags

I change correct answer after this long because in a new project, I had to do the same in the old way, and I finally get this code to works fine by creating a simple app in facebook:

Info for this sample apps: Facebook Send Dialog

APP_ID: Facebook app Identifier
http://www.THEPAGE.com: This would be my domain

$('#share_button').bind('click', function(e){
        e.preventDefault();
        var title = 'Title I want';
        var im_url = 'url_to_image';
        var facebook_appID = 'YourFacebookAppID'
        url = "https://www.facebook.com/dialog/feed?app_id="+ facebook_appID +    "&link=" + encodeURIComponent("http://www.THEPAGE.com")+ 
                    "&name=" + encodeURIComponent(title) + 
                    "&caption=" + encodeURIComponent('Shared from MY_PAGE') + 
                    "&description=" + encodeURIComponent('DESCRIPTION') + 
                    "&picture=" + encodeURIComponent("http://www.THEPAGE.com" +im_url) +
                    "&redirect_uri=https://www.facebook.com";
        window.open(url);
    });

Facebook app is needed to do this

To create your facebook app you need to register as developer and create the app visiting the next link:

Facebook Developer APPS

Set your page up with proper Open Graph meta tags.

This should work with facebooks share scripts. This will also show correct title, image and description of your pages when people post direkt links on facebook without using share buttons.

<meta property="og:title" content="title" />
<meta property="og:description" content="description" />
<meta property="og:image" content="thumbnail" />

I recommend you check out the facebook documentation https://developers.facebook.com/docs/web/webmasters/ https://developers.facebook.com/docs/plugins/share-button

I agree with other answers, use the OpenGraph Protocol

  1. However, if it doesn't work make sure your URL is publicly visible.
  2. If it still doesn't work and you are absolutely sure your meta tags are correct that means Facebook cached your page.
  3. To remove Facebook cache go to the Facebook Object Debugger page and paste your link. By doing this Facebook will force its cache to be refreshed and show you values of your meta tags. That should fix your problem.

Well, I am in the similar situation with you... The sharer.php with customized title and description was working up to a few days ago, and since then, only the OG metada are showing up, when they exist !

If you can, I suggest you to use the official version of the sharer URL, which now only accepts the shared URL in the query string, e.g.: https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fparse.com

See https://developers.facebook.com/docs/plugins/share-button/#faqdialog

Then you'll have to set up the Open Graph metadata on your page.

You can check how Facebook process your page with their debug page : https://developers.facebook.com/tools/debug/

edit :

Custom parameters in the sharer.php URL are officially not supported anymore : https://developers.facebook.com/bugs/357750474364812

Ibrahim Faour - Developer Support Engineer at Facebook

We have changed the behavior of the sharer plugin to be consistent with other plugins and features on our platform.

The sharer will no longer accept custom parameters and facebook will pull the information that is being displayed in the preview the same way that it would appear on facebook as a post from the url OG meta tags.

The easiest way to solve this is to use the feed dialog: https://developers.facebook.com/docs/sharing/reference/feed-dialog

I have posted this in another question too because I wasted hours today trying to figure this out. Hopefully it will solve someone's time. You need APP Id.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!