Home » Android » Android Facebook app: access token expiry ( expires_in ) is always 0

Android Facebook app: access token expiry ( expires_in ) is always 0

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am developing an app which uses facebook integration. I am trying to receive the access_token and expires_in tokens from the facebook library classes. Once i am logged in I get the access_token correctly but i always get expires_in token always 0. And because of that I isSessionValid() method always returns false. Kindly let me know if anyone has faced this issue and solved it.

My code runs perfectly fine when i do not have the Facebook app installed in the emulator. I get the webview and I can log in and update status. But when I install Facebook app, clicking on the update status menu option opens the Facebook app, I get redirected to the permissions page and then I get an error saying ” Failed to receive access token”. This is infact because of the expires_in token being 0.

i do not want to ask the users of the app to uninstall the Facebook app if they have installed. kindly let me the solution to this problem.

Thanks,
Punit

How to&Answers:

If you put permission offline_access, the token expiry is 0.

For any one else having this issue (if you had put offline_access permission and later removed) follow the steps:

  • Go to your facebook profile setting and remove your app.
  • and then do login again.
  • Give permission to your app again.

Alternately you can do this:

  • Go to your facebook profile setting > Apps > Your_App and remove “Access my data any time” permission.
  • Save changes made.
  • Re-run Your_App(i.e. with no offline_access permission now).

Answer:

Have you mentioned Key Hash in the app that you created on facebook? If not, create a valid one and mention it. This usually occurs because of the new update features of facebook, However, older versions of facebook work well each time. You can check this by uninstalling updates on your facebook app, and run your code. It still works fine. Learn more from here