How to access Facebook page posts with app credentials? - facebook

I've been working on getting an old server-to-server Facebook app working which was previously used to load a feed of page posts for pages we own, but even after completing the review for manage_pages access I still get the error "This endpoint requires the 'manage_pages' permission or the 'Page Public Content Access' feature" when I try to access the feed via
https://graph.facebook.com/[page_id]/posts?access_token=[app access token]
or
https://graph.facebook.com/[page_id]/feed?access_token=[app access token]
I've tried generating the app access token with the Graph API explorer and also tried using [app ID]|[app secret] as the access token, but get the same result either way. Is there something I need to do to grant the app manage_pages access for specific pages now facebook's reviewed it, or is there something else I'm missing? The user that created the app can access the data if using a page access token, but since they removed the ability to create permanent page access tokens that's not really a viable option
edit: Looking into the documentation, it seems I should be able to request a page access token using the app authentication now that it's been approved for manage_pages permissions. However, trying to access one with https://graph.facebook.com/v5.0/[page ID]?fields=access_token&access_token=[app access token] also generates the manage_pages or Public Content permissions error, which seems like it would suggest the app doesn't actually have manage pages permissions?

Related

Getting page access_token for a Facebook page (using Graph API)

I am trying to access a public FB community page and display the images on web page, example-http://www.codeofaninja.com/2011/06/display-facebook-photos-to-your-website.html
My site is being developed in java, so I am looking for a core java solution to do something like this.
My site does not prompt for the user to login via Facebook or authenticate. I am simply trying to display all the images from my own album on my website.
I have created an FB app, and then created a community page on which I have my pictures.
I am struggling to I authenticate from the backend code of my with my app or page. My app has user_photos permission and the App Type (Apps->Your APP->Advanced->App type) is Web.
Here are the things I tried using graph API:
1) Get access token
https://graph.facebook.com/oauth/access_token?client_id=ABC&client_secret=XYZ&grant_type=client_credentials
2) Then use access token to get access to the page and its albums, but the above gives me app access_token. As mentioned on Graph API documentation for Page it requires a page acess_token, but I am not understanding how do I get the page_access_token via an app access_token with a backend application.
After Page access token is retrieved I can use the following call to retrieve all photos.
https://graph.facebook.com/PAGE_ID/photos?access_token=<page_access_token>
You can make the following Graph API call To get the page access tokens for all the Pages a particular user admin.
https://graph.facebook.com/user_id/accounts?access_token=<user_acess_token>
the app access token that you're retrieving from
https://graph.facebook.com/oauth/access_token?client_id=ABC&client_secret=XYZ&grant_type=client_credentials
can be used to access the public data on a page - you don't need a specific 'page' access token.
this page https://developers.facebook.com/tools/explorer/ is handy for testing things out - plug in the app access token and the page url to try it out
but I am not understanding how do I get the page_access_token via an app access_token with a backend application.
Not at all …
To get a page access token, you have to have a user access token with manage_pages permission first.
(If you get a long-lived user access token, and use that to get the page access token, then the latter will not expire by default.)

How do I grant my app permissions on pages or groups I created?

I have an app, and I can write to user's walls with it, having requested the publish_stream permission when they sign in.
I've also created a page and a group, and would like my app to be able to write to those. (Specifically, I want my back-end server to post some updates to those periodically, without a user being involved.) The ability to do this seems to be implied by the descriptions of the /feed parts of those here https://developers.facebook.com/docs/reference/api/page/ and here https://developers.facebook.com/docs/reference/api/group/ . However, I can't seem to find a way to authorize the app to write to these pages. Those docs say it can be done if you have publish_streams and manage_pages. OK, but how do I grant those to my app?
In the user case, you request those permissions when the user signs in via the OAuth flow. However, the page and the group never sign-in, so there's no way for them to grant the app permission. I looked around the settings pages for the group and the page, and couldn't find anything that will let me add the app. So how do I give the app the required permissions to post to the group and the page?
Found it!
http://developers.facebook.com/docs/reference/api/application/
http://developers.facebook.com/docs/howtos/login/login-as-page/
"Application Page Access Tokens
To perform the following operations as an Application Page, and not the current user, you must use the Application's Page access token, not the user access token commonly used for modifying Graph API objects nor the Application access token. This access token can be retrieved by issuing an HTTP GET to /USER_ID/accounts with the manage_pages permission. This will return a list of Pages (including Application profile pages) to which the user has administrative access, along with an access_token for each Page.
Note: Applications that are configured as Native/Desktop apps will not be able to make API calls that require an application access_token."
So:
I went to http://developers.facebook.com/tools/explorer/ and, as me, created an access token with "manage_pages" permission.
I then went to https://graph.facebook.com/$myname/accounts?access_token=$accesstoken
and it gave me a list pages and apps that I had given permission to. I copied the access_token from the relevant page, and pasted that into my code, so that the server-side create event code always used that access token.
And it worked!

Public Access Token for Facebook, Permissions

I'm new to the Facebook Graph API!
I want to display the 5 latest news feed items from my public Facebook page. I understand you can do that through https://graph.facebook.com/cocacola/feed/?limit=5, but it requires an access token, however, https://graph.facebook.com/cocacola doesn't.
When these access tokens are generated through Facebook's Graph API Explorer, what permissions are given for the token? Just the information already displayed in the above link?
So would it be safe to use the access token via cURL's PHP? I only need read access. Would it be insecure to display the access token in the source code? I'm confused as to why the latter link doesn't need an access token while the /feed/ does, even though it's a public facebook page.
when you use your app in a website there is a parameter that defines how much access you have from the user, u can set up params like, email, photo_stream, friend_stream, etc. when the user accepts the conditions, the generated AUTH TOKEN has permisions from that scope.

Facebook: Get access token to post as a page

Is it possible to somehow get an access token to use the facebook api like a user that clicked "use facebook as "?
What I'm trying to do is to allow my website to post messages to the facebook page's wall. I already have an app which I use to allow my users to login with their FB account. However, I'd prefer not to require a page admin to authorize full manage_pages to my app. I already added the app to my FB page, but there are no options to give that app some permissions for my page.
Of course it's possible.
In the official documentation page about Permissions it's written:
Page access_token
An access_token used to manage a page. This is used
when you want to perform an operation acting as a Page. This access
token is retrieved by issuing an HTTP GET to /USER_ID/accounts or to
/PAGE_ID?fields=access_token with the manage_pages permission. Getting
/USER_ID/accounts will return a list of Pages (including app profile
pages) to which the user has administrative access in addition to an
access_token for each Page. Alternatively, you can get a page access
token for a single, specific, page by issuing an HTTP GET to
/PAGE_ID?fields=access_token with the manage_pages permission (you
must ask for the access_token field specifically via the fields=
parameter). See the documentation for the Page object for more
information. NOTE: After November 1, 2011, manage_pages permission
will be required for all access to a user's pages via this connection,
i.e. for both reading the user's pages and also retrieving
access_tokens for those pages. See the documentation for the User
object for more information.

How to use Facebook API to publish an event on a page after logging-in a user?

I used the graph api in order to connect the user and publish an event on its wall.
But if I am connected as a page, I get this error message : "You need to be connected as a user and not as a page to run this app"
But I which I could publish my event on a fan page.
Here is my TOKEN_URL
How shoud I do to be able to publish on my fan page.
How can I enable that ?
To publish "on behalf" of a Page, you need to use a Page access token. To get a Page access token, first get an access token for a user with the manage_pages and publish_stream permissions:
https://graph.facebook.com/oauth/authorize?client_id=YOUR_APP_ID&
redirect_uri=YOUR_REDIRECT&scope=manage_pages,publish_stream&type=user_agent
Then, using the access token you get as a result, do a GET of:
https://graph.facebook.com/me/accounts?access_token=ACCESS_TOKEN_FROM_STEP_1
Here, you'll find the list of the Pages the user is an admin of. Here you can grab the access token for one of these Pages. Now calls you make will be made on behalf of the Page. Now anything you try to post will be posted as the Page. If you are trying to create events, you may also need the create_event permission.
To see how this works, you can test this out using these URLs in your browser or in the Graph API Explorer.
You need to get an offline access token with the manage_pages permission for the user that created/owns the fan page. After obtaining the user's access token, then you need to get the page's access token.
See this answer with code for details:
How can I use 'manage_pages' permission with the SDK on Facebook?
You could log in as the administrator of the page and create an offline access token for that user.