Facebook: Post to Page as Page - php

I am trying to post to a facebook page from my facebook application.
I have given the app the manage_pages and publish_actions permissions.
I retrieve the page ID and access token via a request to /me/accounts and then attempt to post to the page using:
POST https://graph.facebook.com/{PAGE_ID_HERE}/feed
?access_token={PAGE_ACCESS_TOKEN_FROM_PREVIOUS_REQUEST}
&message=test
but I get the following error:
The user hasn't authorized the application to perform this action
The page access token appears to be valid:
Why do I get this error? How should I proceed?

The solution was to add the publish_stream permission too. I didn't think this was needed as publish_actions is supposed to replace that; but it started working once it was added.
Facebook used to have a permission called publish_stream, publish_actions replaces it.
Quote from 18th July 2013.

Related

How to post to my own page using the Facebook API

I would like to post updates to a Facebook Page I own, using the API.
I followed the instructions in this answer to obtain:
a short-lived access token for my user, making sure to grant permissions for publish_stream and manage_pages
a long-lived access token, which the token debugger actually shows as never expiring
a Permanent Page Access Token specific for my page, which again is shown as never expiring
I can use the long-lived access token to post to my wall, but neither that nor the specific page access token allow me to post to my page.
If I try to use the personal long-lived access token to post to my Page ID, it returns OK and an actual post ID, but the post never appears on the page.
If I try to use the page access token to post either to /me/feed (which should be the page) or to the page ID, I get #200 The user hasn't authorized the application to perform this action which I clearly did.
What am I doing wrong?
Do I need to submit my app for review? How can I do so, when I don't even have an "app"? It has no public facing website, nothing, because it's only a single script for my own personal use, which I'd like to use to update my page.
according to the docs you will need publish_pages permission to post as page from api v2.3 . Prior, it needed permission publish_actions in addition to manage_pages. Now they have introduced publish_pages specifically for that purpose. .
A page access token with publish_pages permission can be used to
publish new posts on behalf of that page. Posts will appear in the
voice of the page.

Automatically post on wall - Facebook Graph API PHP SDK v4

I'm building an application for an event so they can directly post their news messages on facebook. I'm trying to use de php SDK V4 for this but there are some parts of the login process I don't understand (still couldn't find a solution after searching for several hours).
My Problem is in the login process. First you have to specify which applicaton you are and give your application secret. Than you have to login to facebook with an account.
But which account should I use for that? The one of their event? Mine?
(I'm an admin of the events page) (this means that all messages will
be posted from mine account while i'm not the poster...sounds pretty
weird..)
Which method should I use to login into facebook? There is a veriaty of methonds like the FacebookRedirectLoginHelper(), the FacebookCanvasLoginHelper() or the Javascript one. However as far is I understand all these helpers for your users to login to their facebook accounts and that's not what I want.
During my search I found some an example of someone who is making a similar system (Facebook Graph API PHP SDK v4 - Post on Page). He/She uses the folowing piece of code for getting a facebook session:
FacebookSession::setDefaultApplication('{APP ID}','{APP SECRET}');
$session = new FacebookSession('{Page Access Token}');
This suggests that you don't need to login into facebook by user but only need a Page Acces Token. However if I understand it correctly (correct me if I'm wrong), to get a Page Acces Token, you first need an User Acces Token (https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens). To get an User Acces Token you should be logged in, and than we're back to question 1 and 2 in the beginning of my story.
Or can I just get a Page Acces Token using the following api request (according to https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens)
GET /{user-id}/accounts
Using a random user-id as long as the page admin gave this user permission to generate such a token (so the user related to "user-id" shouldn't be logged in while retrieving the Page Acces Token?) .
Sounds like you'll need to use the following flow:
Have the page admin log in with their Facebook account. Make sure to request the manage_pages extended permission. This will give you access to the pages they admin.
Once they grant access to your app, you'll get a short lived user access token. Exchange it for a long lived user access token.
Get the list of the user's pages with /me/accounts. Each page will have an access_token field returned with it. These are all page access tokens. We want to use a long lived user access token to get this list so that all the page access tokens returned will not have an expiration date. They live forever! :)
Use the page access token to post to the wall of the page if you want to post as that page. Use the user access token to post to the wall of the page if you want to post as that user.
And the Facebook Query Builder might make this whole process a lot easier. :)
Hope that helps!

Autopost on facebook users wall

i have a task to automatically post from my site on users wall they are logged in the same browser once giving all the permissions it should never ask again for giving permissions means all the next post should be posted automatically on that users wall. can anyone help me ?
Rquire a stream_publish permission (for example with redirect) and do a graph api call of type post to /me/feed/ by PHP Facebook API.
After receiving permission you shuld exchange your access token to long-lived access token which will be fine for about 60 days.

Long term access token for fan page. manage_pages permission

I want to create a long term page access token. I have followed these steps.
Find your user Token(2 Hours)
developers.facebook.com/tools/access_token/
Generate long term Token (2 months)
graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
EXISTING_ACCESS_TOKEN is what you get from Find your user Token above.
Page Access Token
Go to https://developers.facebook.com/tools/explorer?method=GET&path=me%2Faccounts
Plug in long term access token
Enter https://graph.facebook.com/me/accounts in the second text box
Click on submit
Json data will be returned
From that select the access token of your Fan page
My problem is that when I enter in the long term access token the Graph API Explorer I only get back the name , category and id. And not the access token. Which leads me to believe the long access token does not have the manage_pages permission but when I go to set it. I get back a short term token with the permission set.
Any ideas?
Are you sure that you're not using the wrong token or the wrong permissions on the request to /me/accounts?
Check with a call to /app (to see if it's the correct app) and /me/permissions to check it's the right permissions, provided you have the the manage_pages permission and it's the long-expiry token (which you can check in Facebook's Debug Tool) it should be OK

Authorize facebook app to post to page wall, but not to users walls

I have a facebook app which can post to the wall of a page by using the administrators 'publish_stream" permission. However I don't want to have the ability to post all over a user's wall, only the pages they control.
Since this is being done automatically I will need a permanent token (offline_access) and obviously the publish_stream permission. But I'm unsure how to request this.
I have seen some applications, like the notes app in pages which have a setting for allow this app to post on wall. This would be easier, but otherwise does anyone know how I can request publish_stream permission for a page via the graph api?
For example, this is the request I use to get the user authorization code before requesting a token. I can't find an equivalent to request authorization for a page though.
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream
You can't get permission to access only a page's wall / news feed without access to the user's also. If you're worried about "accidentally" posting to the user's wall and not to the page, you can make sure you use the access_token provided in the /me/accounts endpoint for your user.
So, your choices are pretty limited here if you want to use the offline_access permission to post to a pages wall. Limited, as in, you need to have publish_stream and manage_pages permissions.

Categories