Reputation: 1049
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.
Upvotes: 1
Views: 216
Reputation: 38135
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.
Upvotes: 1