如何自动发布到时间轴?

发布于 2024-12-19 16:39:01 字数 1730 浏览 3 评论 0原文

http://www.independent.co.uk/http://www.guardian.co.uk/ 有一个应用程序,如果您在其网站上阅读文章,它会写入到您的个人资料/时间线“X 已阅读 Y” Z”。

现在我可以通过一个按钮写入时间线。我也可以自动执行此操作(但每次他们转到我不需要的文章时都会发生这种情况)。但是我需要添加一些逻辑,如下所示

  1. 如果用户登录但应用程序未授权
    • 显示授权应用程序的按钮
  2. 如果用户登录且应用程序授权并且首次访问文章
    • 自动将“X 已在 Z 上阅读 Y”发布到他们的个人资料和 FB
  3. 如果用户登录且应用程序授权并再次访问文章,则
    • 不要发布任何内容

这有意义吗?有这方面的例子吗?所以基本上按时间表发布不是问题,这只是我需要进行的各种检查。

编辑

好的,出于某种原因,这有效(用于检查它们是否被授权),但是如果我取出 alert('test'); 部分,它就不会'不工作。有什么想法吗?

<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=123456789";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

alert('test');

    FB.init({ 
        appId:'123456789', cookie:true, 
        status:true, xfbml:true, oauth:true
    });
    
FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
    alert('Logged in and connected');
    $(read);
  } else if (response.status === 'not_authorized') {
    alert('Logged into FB but not authorised');
  } else {
    alert('Not logged into FB');
  }
});
</script>

好的,部分工作了。有一些小问题,但现在的主要问题是检查他们是否已经在时间轴上发布了特定操作。如果他们已经阅读了,则不要再发布其他内容,例如,因此,当他们第一次阅读文章时,会添加状态“乔恩已阅读网站上的文章”。但是,如果他们再次访问它,它就不会被添加

http://www.independent.co.uk/ and http://www.guardian.co.uk/ have an application where by if you read an article on their site, it writes to your profile/timeline that "X has read Y on Z".

Now I can write to the timeline with a button present. I can also do it automatically (but this happens each time they go to the article which I don't need). However what I need to add is some logic as shown below

  1. If user logged in but app not authorised
    • Show a button to authorise application
  2. If user logged in and app authorised and visiting article for first time
    • Automatically publish "X has read Y on Z" to their profile and FB
  3. If user logged in and app authorised and visiting article again
    • Don't publish anything

Does this make sense? Any examples of this around? So basically pulishing to the timeline isn't an issue, it's just the various checks I need to put into place.

EDIT

Ok, for some reason this works (for checking of they are authorised or not) but if I take out the alert('test'); part, it doesn't work. Any ideas?

<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=123456789";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

alert('test');

    FB.init({ 
        appId:'123456789', cookie:true, 
        status:true, xfbml:true, oauth:true
    });
    
FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
    alert('Logged in and connected');
    $(read);
  } else if (response.status === 'not_authorized') {
    alert('Logged into FB but not authorised');
  } else {
    alert('Not logged into FB');
  }
});
</script>

Ok, got it partly working. There are some slight niggles but main issue now is to check whether they have posted a specific action to the timeline already. If they have then don't post another e.g. So when they go to an article first time, the status "Jon has read an article on the Site" gets added. However if they go to it again, it doesn't get added

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠 2024-12-26 16:39:02

这违反了 Facebook 平台政策。参见第四节第 3 部分:

如果用户授予您发布权限,您在代表用户采取任何操作(例如发布内容或创建活动)之前仍必须获得该用户的同意。

在未事先征得用户许可的情况下,您无法将内容发布到用户的时间线\墙上。 《独立报》和《卫报》与 Facebook 达成了一项独特的安排,使它们免受这些限制。

这种情况会让你收到措辞强硬的电子邮件警告,或者更严重的是,开发者帐户被暂停。

查看平台政策和促销清单总是好的在开始一个新项目之前。

This is against the Facebook Platform Policy. See section IV part 3:

If a user grants you a publishing permission, you must still obtain consent from the user before taking any action on the user's behalf, such as publishing content or creating an event.

You can not post to the user's timeline\wall without first asking them permission. The Independent and The Guardian have a unique arrangement with Facebook that exempts them from these restrictions.

This is the kind fo thing that will get you a strongly worded email warning, or more severely, a developer account suspension.

Its always good to have a look at the Platform Policies and Promotions Checklist before starting a new project.

以酷 2024-12-26 16:39:02

由于代码中存在竞争条件,您的代码仅适用于警报。
您正在异步加载SDK(您应该这样做),但随后尝试通过立即调用FB.init同步使用它。

您需要定义一个函数fbAsyncInit,在其中调用FB.init。这将确保您在加载 SDK 之前不会尝试调用 FB.init

除此之外,这一切都是为了从用户那里获得正确的权限,并遵守 Facebook 的政策。从技术上讲,这都是非常基本的东西。

Your code only works with the alert due to a race condition in your code.
You are loading the SDK asynchronously (which you should), but then try to use it synchronously by calling FB.init immediately.

You need to define a function fbAsyncInit, in which you call FB.init. This will ensure that you don't try to call FB.init before the SDK is loaded.

Other than that, this is all about getting the right permissions from the user, and following Facebooks policies. Technically it's all pretty basic stuff.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文