在 Facebook 分享和发布后重定向用户 [英] redirect user after facebook share and publish

查看:29
本文介绍了在 Facebook 分享和发布后重定向用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

推荐答案

<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 初始化是正确的 :(

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

这篇关于在 Facebook 分享和发布后重定向用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆