1

I have created a tool that allows me to do automatic social media marketing by posting to Twitter via API. I would now like to do that same thing and share the extended message/tweet to my personal FB profile as well as the FB page. I have figured out a way to post to FB using Koala, the only thing is that the token constantly expires. Is there a way where I can continuously be connected like I am with the Twitter API?

Any thoughts, ideas, or suggestions are appreciated.

Fdwillis
  • 1,050
  • 9
  • 21
  • http://stackoverflow.com/questions/10249778/facebook-token-expiration-and-renewal-with-koala-and-omniauth-facebook – rkamun1 Jun 05 '15 at 13:53
  • I dont have "users" , this is just for my own purposes. This is essentially just hosted code online with no portal for login/logout. – Fdwillis Jun 05 '15 at 13:56
  • I was looking at the first answer, "What I have is a before_filter that.....". That doesn't use users, it just resets the token if it has expired. – rkamun1 Jun 05 '15 at 14:04
  • ahh ill go take another look – Fdwillis Jun 05 '15 at 14:05
  • yea im not sure about that, I dont have omni-auth and would prefer not to have to install that JUST to store one token. Maybe I am over thinking this? I'm still pretty new to rails – Fdwillis Jun 05 '15 at 14:11

1 Answers1

1

Facebook has a long-lived access tokens:

User access tokens come in two forms: short-lived tokens and long-lived tokens. Short-lived tokens usually have a lifetime of about an hour or two, while long-lived tokens usually have a lifetime of about 60 days.

As you can see, even user's long-lived token will expire eventually. So it's up to you to either build a small tool to notify you when a token is about to expire or not. But in all cases, this can be done with cURL pretty easily (I have no ruby-on-rails experience): https://developers.facebook.com/docs/facebook-login/access-tokens#extending

  • Start with a short-lived token generated on a client and ship it back to your server.
  • Use the user token, your app ID and app secret to make the following call from your server to Facebook's servers:
GET /oauth/access_token?  
    grant_type=fb_exchange_token&           
    client_id={app-id}&
    client_secret={app-secret}&
    fb_exchange_token={short-lived-token}

PLEASE NOTE: that page access tokens generated from a long-lived user access tokens will NOT expire, see: https://developers.facebook.com/docs/facebook-login/access-tokens#extendingpagetokens

To get a longer-lived page access token, exchange the User access token for a long-lived one, as above, and then request the Page token. The resulting page access token will not have any expiry time.

ifaour
  • 38,035
  • 12
  • 72
  • 79