2

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.

  1. 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..)
  2. 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?) .

Community
  • 1
  • 1
Wobbert
  • 53
  • 1
  • 7
  • Your question is not clear. Where exactly you want to post? Event? or a page? If page, your own page, or any user's page? It's not clear at all! – Sahil Mittal Jun 26 '14 at 07:22

1 Answers1

1

Sounds like you'll need to use the following flow:

  1. 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.
  2. 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.
  3. 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! :)
  4. 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!

SammyK
  • 983
  • 11
  • 20
  • Thanks a lot. It sounds a lot more clear now. I'll give it a try! – Wobbert Jun 30 '14 at 20:19
  • I also needed the "publish_actions" extended permission. Besides that, the workflow you listed was clear and it works now. Thanks a lot! – Wobbert Jul 05 '14 at 20:32