在Facebook上自动发布(代表用户) [英] Auto post (user behalf) on facebook

查看:84
本文介绍了在Facebook上自动发布(代表用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索,但没有找到答案. 我有一个提供实时跟踪服务的网站. 我已经使用了javascript facebook共享供稿,以便用户可以在其Facebook页面上发布其活动和其他活动.

I've been searching and haven't found an answer. I've a website that has a livetracking service. I already use the javascript facebook share feed so that users can post on their facebook page their and others activities.

我想知道目前是否可以代表用户发布(我知道过去是可能的).我已经有一个获取长命令牌的过程.

I wonder is at the moment (I know it had been possible in the past) is possible to post on user behalf. I already have a process to get a long lived token.

目标是在用户开始/结束活动时提供自动发布的功能,通知其关注者.

The goal is to give the ability of auto post when users start/end activities, informing their followers.

推荐答案

自2018年8月起更新:

publish_actions不能再使用.无法再自动将内容发布在用户的个人资料上. Facebook建议改为使用share dialog,这需要用户确认每个帖子. Facebook将向用户显示一个窗口以批准该帖子.
使用share dialog:

The publish_actions can not be used anymore. It is not possible to post content on a user's profile automatically anymore. Facebook suggests using the share dialog instead, which requires the user's confirmation for every post. Facebook will show a window to the user for approving the post.
Example code for using the share dialog:

FB.ui({
  method: 'share',
  href: 'https://developers.facebook.com/docs/',
}, function(response){});

包含所有参数的完整文档可以在这里找到: https://developers.facebook.com/docs/sharing/reference/share-对话框

The full documentation with all parameters con be found here: https://developers.facebook.com/docs/sharing/reference/share-dialog

只有在该用户已授予其发布权限的情况下,第三方才能代表该用户发布内容.

A third party is only able to post content on behalf of a user if that user has granted permission for doing so.

第一步是注册一个应用程序,以防您尚未注册它: https://developers.facebook.com/apps/

The first step is to register an app, in case you haven't done it already: https://developers.facebook.com/apps/

Facebook将向用户显示提示,并要求他向该应用程序授予权限.在Facebook应用程序中,您需要请求publish_actions权限. 这将为您提供访问令牌,以该用户的名字在该用户的墙上发布帖子.

Facebook will show a prompt to the user and ask him for giving permissions to that app. In the Facebook app, you need to ask for publish_actions permissions. This will give you an access-token to publish posts on the wall of that user in his name.

为此,您可以使用Graph API:

For doing so you could use the Graph API:

POST graph.facebook.com
     /{user-id}/feed?
     message={message}&
     access_token={access-token}

如果您使用的是JavaScript SDK,则代码可能类似于以下内容:

If you are using the JavaScript SDK, the code could look similar to this:

FB.init({ 
    appId: 'insert your appID value here', 
    cookie: true, 
    xfbml: true, 
    status: true });    

FB.api(
    "/{user-id}/feed",
    "POST",
    {
        "message": "This is a test message"
    },
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);

在这里,您将找到有关参数和响应的详细信息: https://developers.facebook.com/docs/graph-api/reference/v2.9/user/feed#publish

Here you will find detailed information on the parameter and responses: https://developers.facebook.com/docs/graph-api/reference/v2.9/user/feed#publish

这篇关于在Facebook上自动发布(代表用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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