Ramanvir Sodhi
Ramanvir Sodhi

Reputation: 29

redirect user after facebook share and publish

How can I redirect a user to a specific URL if the user publishes and to a different URL if he skips?

https://www.facebook.com/dialog/feed?
app_id=123050457758183&
link=https://developers.facebook.com/docs/reference/dialogs/&
picture=http://fbrell.com/f8.jpg&
name=Facebook%20Dialogs&
caption=Reference%20Documentation&
description=Using%20Dialogs%20to%20interact%20with%20users.&
message=Facebook%20Dialogs%20are%20so%20easy!&
redirect_uri=http://www.example.com/response

The above example redirects the user to same URL whether he clicks publish or skip.

I tried the example given below:

   <script> 
  FB.init({appId: " id", status: true, cookie: true});

  function postToFeed() {

    // calling the API ...
    var obj = {
      method: 'feed',
      link: 'link to share',
      picture: 'gggg',
      name: 'ggg',
      caption: 'ggg.',
      description: 'ggg.'
    };

    function callback(response) {
      document.getElementById('msg').innerHTML = "Post successfully published, Post ID: " +     response['post_id'] + " click here";

var str = "Click here to activate your new timeline facebook profile!";
document.write(str.link("redirection url here"));


 }

    FB.ui(obj, callback);
  }

But the above example also is unable to give results.

Upvotes: 1

Views: 13527

Answers (3)

Ketan Niruke
Ketan Niruke

Reputation: 19

<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> 

Upvotes: 0

Ketan Niruke
Ketan Niruke

Reputation: 19

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>

Upvotes: 1

Alexander Nenkov
Alexander Nenkov

Reputation: 2910

<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 :(

Upvotes: 2

Related Questions