redirect user after facebook share and publish

江枫思渺然 提交于 2019-11-29 12:53:11
<script type="text/javascript">
FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});
  function share_me() {
    FB.ui({
      method: 'feed',
      app_id: 'YOUR_APP_ID',
      link: 'SHARE_URL',
      picture: 'PIC_URL',
      name: 'SHARE_NAME',
      caption: 'SHARE_CAPTION',
      description: 'SHARE_DESCRIPTION'
    },
    function(response){
      if(response && response.post_id) {
        self.location.href = 'SUCCESS_URL'
      }
      else {
        self.location.href = 'CANCEL_URL'
      }
    });
  }
</script>";
  <div onclick="share_me()">Share</div>

A bit different from yours but I hope you get the idea. We're using our own framework so I can't guarantee the FB initialization is correct :(

window.fbAsyncInit = function() {
    FB.init({
      appId            : 'FACEBOOK_APP_ID',
      autoLogAppEvents : true,
      xfbml            : true,
      version          : 'v3.3'
    });
  };
	function share_me(url,productlink) {
	FB.ui({
  method: 'share_open_graph',
      app_id: 'FACEBOOK_APP_ID',
      link: 'REDIRECT_URL',
       action_type: 'og.likes',
  action_properties: JSON.stringify({
    object:
	  {
		 'og:url': productlink, 
		'og:image': url 
	  }
  })
	
}, function(response){
  // Debug response (optional)
  if(response && response.post_id) {
        self.location.href = 'SUCCESS_URL'
      }
      else {
        self.location.href = 'CANCEL_URL'
      }
		
});
	self.location.href = 'REDIRECT_URL';	
	}
<script async defer src="https://connect.facebook.net/en_US/sdk.js"></script>

<div onclick="share_me()">Share</div>

<a href="https://www.facebook.com/dialog/share?app_id=YOUR_APP_ID&display=popup&href=<?php echo get_permalink($product->id) ;?>&redirect_uri= REDIRECT_URL "><span>Share me</span></a> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!