Javascript SdK facebook Oauth 2.0 - facebook

I got auth token for facebook account of a user I stored it in database but when i used it after few days it throws an error exception. How to get long lived access token?
Error is the following:
Received Facebook error response of type OAuthException:
Error validating access token: Session has expired at unix time 1333612800.
How to get a token that doesn't expire?

You cant have a token that doesnt expire anymore, you can only generate codes that last max 60 days.

Related

How to get my own Facebook user access token indefinitely?

I want to pull my most recent images from facebook's api for my personal website. I cannot seem to find a way to only authenticate my user without the login dialog. Does anyone know if this is possible? I can generate my user access token inside the graph API Explorer, but it expires in 1 hour.
How to get my own Facebook user access token indefinitely
You cannot!
But you can extend this token that will be valid for 60 days - called the long-lived token. So, if a user visits your application at least once in 60 days you can have the access to user's data indefinitely.
Simple call to get the long-lived user access token-
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
Refreshing this token- The user have to go through the login process again (calling login API) to get the short-lived token and then perform the same exchange for a fresh long lived token with 60 days expiry.
You can also debug your token anytime with-
GET /debug_token?
input_token={input-token}&
access_token={access-token} // a valid user access token or app access token

Error: The client token cannot be used for this API

I am trying to publish Facebook Timeline actions using the app access token instead of the user's access token (so that I don't have to deal with expiring sessions), as described here:
https://developers.facebook.com/docs/opengraph/using-app-tokens/
This was working fine, but stopped working a few days ago, now giving me this error:
The client token cannot be used for this API
Any ideas on why this is happening, and how to fix it?

Facebook session expiration error when try to post actions to open graph using 'App access token'

I am facing this error with some of my users, the case is as following:
I use facebook "App access token" to post actions to facebook Open Graph instead of the user access token because app access token don't expire according to facebook documentation unless you refreshed the app secret, I use the follwoing Post url to post actions
https://graph.facebook.com/user_facebook_id/App_Namespace:action_name?FBOG_Object=FBOG_OBJECT_URL&access_token=app_access_token
Some of the actions do appear on facebook, but for some users the actions fails to post and return the following message:
{ "error": { "message": "Error validating access token: Session has expired at unix time 1345759200. The current unix time is 1345925578.", "type": "OAuthException", "code": 190, "error_subcode": 463 } }
What am I doing wrong? Why do I have an expiration error although am using the app access token? Should I worry for user permissions?
After checking the servers it seems that the code that uses the app token was not deployed and the code that uses the user token is still there.
The app token does not expire unless the app owner took some action.
https://developers.facebook.com/docs/authentication/applications/
Error message clearly shows that your access token expired and you need to get another one.
However you can handle this issue : Access token expiration
Also if you are looking for a long life token you need to provide some more parameters while authorizing the application to a new user.
offline_access parameter can be included in a request but now it's been deprecated by facebook. Removal of offline access

How to get a long term access token

Sience Facebook canceled offline_access scope,The access token I get can only available for 2 days.I read their blog,and tried to refresh token every hour.But every time the token I get is just the same as I sent to.and it expires.
It is strange that IM Plus(http://plus.im/)Never need to refresh token(as long as I registed and add Facebook connect to it,about one month)I wonder how did they do that.I discovered they are still using 'offline_access' scope. Here is their URL to get access token
https://www.facebook.com/dialog/oauth?api_key=119600778096160&app_id=119600778096160&client_id=119600778096160&display=touch&domain=plus.im&locale=en_US&origin=2&redirect_uri=https%3A%2F%2Fs-static.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D6%23cb%3Df3d1b1d90c%26origin%3Dhttps%253A%252F%252Fplus.im%252Ff232f2ca44%26domain%3Dplus.im%26relation%3Dopener%26frame%3Df336857b2c&response_type=token%2Csigned_request&scope=read_stream%2C%20publish_stream%2C%20xmpp_login%2C%20read_mailbox%2C%20offline_access&sdk=joey
So,How to get a long term access token just like they do?
Thanks.

Facebook offline_access but access tokens still expire

I have written an application to manage a user's Facebook notifications. The app requests offline_access as well as manage notifications permissions. My logs have been filling up with Facebook errors. I understand that when a users changes their password the token is going to expire, but what I don't understand is why I am getting these errors:
Facebook Error: Error validating access token: Session has expired at unix time 1320012000. The current unix time is 1320191317.
Facebook Error: (#200) The "manage_notifications" permission is required in order to query the user's notifications.
They are occurring way too often to be users just rejecting the permissions and the access tokens that are expiring have expirations of 0.