How to add facebook share button on my website?

前端 未结 7 1614
情书的邮戳
情书的邮戳 2020-12-02 04:09

I have this code that suppose to work, but doesn\'t work. If this helps you in anyway that would be great.



        
7条回答
  •  旧巷少年郎
    2020-12-02 04:34

    Share Dialog without requiring Facebook login

    You can Trigger a Share Dialog using the FB.ui function with the share method parameter to share a link. This dialog is available in the Facebook SDKs for JavaScript, iOS, and Android by performing a full redirect to a URL.

    You can trigger this call:

    FB.ui({
      method: 'share',
      href: 'https://developers.facebook.com/docs/', // Link to share
    }, function(response){});
    

    You can also include open graph meta tags on the page at this URL to customise the story that is shared back to Facebook.

    Note that response.error_message will appear only if someone using your app has authenticated your app with Facebook Login.

    Also you can directly share link with call by having Javascript Facebook SDK.

    https://www.facebook.com/dialog/share&app_id=145634995501895&display=popup&href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F&redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer
    
    https://www.facebook.com/dialog/share&app_id={APP_ID}&display=popup&href={LINK_TO_SHARE}&redirect_uri={REDIRECT_AFTER_SHARE}
    
    • app_id => Your app's unique identifier. (Required.)

    • redirect_uri => The URL to redirect to after a person clicks a button on the dialog. Required when using URL redirection.

    • display => Determines how the dialog is rendered.

    If you are using the URL redirect dialog implementation, then this will be a full page display, shown within Facebook.com. This display type is called page. If you are using one of our iOS or Android SDKs to invoke the dialog, this is automatically specified and chooses an appropriate display type for the device. If you are using the Facebook SDK for JavaScript, this will default to a modal iframe type for people logged into your app or async when using within a game on Facebook.com, and a popup window for everyone else. You can also force the popup or page types when using the Facebook SDK for JavaScript, if necessary. Mobile web apps will always default to the touch display type. share Parameters

    • href => The link attached to this post. Required when using method share. Include open graph meta tags in the page at this URL to customize the story that is shared.

提交回复
热议问题