6

I am trying to automatically display wall posts from a Facebook page another website. I can use the Graph API explorer to get one manually. When I use the generated token in my code all is well. The problem is the tokens expire quickly. It just isn't practical to get a new code several times a day. I know there is a way to request an access token programatically - in my case via PHP, but all the examples call for an app secret. Since this is a page and not an app, there is no secret.

I have tried this:

https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=MY_CLIENT_ID&redirect_uri=http%3A%2F%2FMY_SITE_URL&scope=user_status

What I get back is this:

{ "error": { "message": "Error validating application. Cannot get application info due to a system error.", "type": "OAuthException", "code": 101 } }

I have tried using Fiddler to intercept the call from the Graph API explorer to see what I need in my code file, but haven't had any luck.

Mike K.
  • 295
  • 2
  • 5
  • 11
  • _“Since this is a page and not an app, there is no secret.”_ – well, then just create an app, makes things a lot easier that trying to “work around” not having an actual app. You don’t need to set up any app pages, canvas or page tab urls – just create the app, and maybe set up a domain for login, and then get access tokens with that app, make them long-lived, and query the Graph API with these tokens. – CBroe Jun 28 '12 at 08:00

2 Answers2

14
  1. Use the app-id to build this link to authorize the managing of pages https://www.facebook.com/dialog/oauth?client_id=MY_CLIENT_ID&redirect_uri=MY_SITE_URL&scope=manage_pages&response_type=token

  2. Exchange token for perm (longer token)
    https://graph.facebook.com/oauth/access_token?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&grant_type=fb_exchange_token&fb_exchange_token=(from link1)

  3. Visit this page, find the PAGE you want to post and copy the new access_token https://graph.facebook.com/me/accounts?access_token= (from link2)

  4. Use this last token (form link3) to post to page as app

  5. Take note as it will expire in 60 days. (FB no longer offering unlimited offline access token)

Edit (2013 Oct 24): 5th point no longer true, Page Access Tokens generated from long-lived User Tokens do not expire.

Edit (Feb 2016): Tokens now "usually" expire in 60 days but can be invalidated at any time.

WackGet
  • 2,667
  • 3
  • 36
  • 50
MPaulo
  • 1,491
  • 14
  • 19
  • Thanks for the fast response. When I try the first step I get "An error occurred. Please try again later." I have tried similar steps in this process and that's the response I have usually gotten. Also, I don't want to manage pages or post to the page. I merely want to read wall posts from the page and post them to another site. Finally, do pages have secrets? I know apps do, but this isn't an app. That's been a major frustration in trying to resolve this, almost every example out there assumes that you are trying to attach to an app, not a page. Thanks again. – Mike K. Jun 28 '12 at 13:04
  • Have you changed the CLIENT_ID and SITE_URL vars? – MPaulo Jul 19 '12 at 03:34
  • Why " 5th point no longer true"??? Really it's expire date is 60 day or unlimited? http://facebooksdk.net/docs/web/handling-expired-access-tokens/ – Elyor Sep 23 '14 at 10:19
1

For graph objects that are not private (public) you can use your app_id as an access_token.

Your app_id never changes so you don't ever have to renew it. The question is is the wall content yours?

If so you can easily use your app_id to accomplish this without having to request an access token everytime.

However, in order to have an app_id you need to create an application on facebook with a facebook developer account. As far as I understand there isnt a way to anonymously make request to the Graph API,

qodeninja
  • 10,946
  • 30
  • 98
  • 152
  • As the web developer for the company I have been given admin access to the page. I suppose I need to better education myself in Facebook terminology. It confuses the hell out of me. I don't understand how creating an app will help, and yet that has been recommended twice now. And even if I do, how do make an association between the app and the existing page? – Mike K. Jul 02 '12 at 04:20
  • Never mind. It makes sense now. I just created an app and requested an access token and the wall posts are working again. Thanks. – Mike K. Jul 02 '12 at 04:47
  • 5
    I have tried to use app_id as access token to post data into my facebook page but I got the error "Invalid OAuth access token. ". If you have any example code, please update. – Jayendra Kainthola Jul 30 '13 at 12:12