Auto post (user behalf) on facebook

心已入冬 提交于 2019-12-25 09:26:37

问题


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.


回答1:


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

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

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 own name.

For doing so you could use the Graph API:

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

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

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



来源:https://stackoverflow.com/questions/44657678/auto-post-user-behalf-on-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!