【问题标题】:redirect user after facebook share and publishfacebook分享和发布后重定向用户
【发布时间】:2012-02-20 20:59:59
【问题描述】:

如果用户发布,我如何将用户重定向到特定的 URL,如果他跳过,我如何重定向到不同的 URL?

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

无论用户点击发布还是跳过,上面的示例都会将用户重定向到相同的 URL。

我尝试了下面给出的示例:

   <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);
  }

但上面的例子也无法给出结果。

【问题讨论】:

    标签: facebook button redirect share publish


    【解决方案1】:
    <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>
    

    与你的有点不同,但我希望你能明白。我们使用的是我们自己的框架,所以我不能保证 FB 初始化是正确的:(

    【讨论】:

    • 我应该用我想将用户重定向到的网址替换//successful post吗?
    • 是的,您可以根据需要使用 self.location.href = 'your_url_here' 或 top.location.href = 'your_url_here'
    • 我之前使用的代码用于在 html 网页中工作。对不起,如果我问一个菜鸟问题......但是如何让上面的代码工作......
    • 对其进行了重新设计。它工作了 99% :) 我只是不确定 FB.init 因为我们在框架中初始化它,我从不使用它:)
    【解决方案2】:

    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>

    【讨论】:

      【解决方案3】:

      &lt;a href="https://www.facebook.com/dialog/share?app_id=YOUR_APP_ID&amp;display=popup&amp;href=&lt;?php echo get_permalink($product-&gt;id) ;?&gt;&amp;redirect_uri= REDIRECT_URL "&gt;&lt;span&gt;Share me&lt;/span&gt;&lt;/a&gt; 

      【讨论】:

      • 添加一些解释,说明此答案如何帮助 OP 解决当前问题
      猜你喜欢
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多