问题
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