How to display the facebook details automatically in android app as long as there is an active access token?

71 views Asked by At

I'm creating an android application in which i am using facebook login.I'm using graph api for this purpose.I want to display the profile picture,name and location of the logged-in user.I have a method for getting the profile information.I want to display the details each time i open my app without calling the login method each time.ie.i want to display the details automatically as long as there is an active access token.How to do this ?

My method for login is working fine.How to display the details automatically as long as there is an active access token ?

2

There are 2 answers

0
DorAyalon On

Use the Session object to create a new Session using your Facebook access token, and token expiry date

1
Gökhan Girgin On

You can store user info in Shared Preferences

for example; You can save user data after login

// this Application Context  
   SharedPreferences preferences  = PreferenceManager.getDefaultSharedPreferences(this);      
   SharedPreferences.Editor editor = preferences.edit();

   editor.putString("name",retrievedName);

   editor.putString("picture",retrievedPicture);

   editor.putString("location",retrivedLocation);

   editor.commit();

Then you can check easily if user authenticated getString(String key, String defValue)

 //if it is null login again
 String name = preferences.getString("name",null);

Or you can use sqlite as well but if you are developing native app it would be better to use facebook android sdk