2
votes

I'm using Facebook SDK 3.0 in my app. I'm able to get user details like access token, email and name through session login example provided in the Facebook Samples. I'm initializing session object and getting access token, email and name on the login page itself. When it's done getting email and access token, I save them in the Shared Preference and send user to the home activity and clear the activity stack.

Now the problem is, User navigate to throughout the app and it lands on a page where he's given an option to share something on his Facebook wall. As of now, the only thing I have is the access token. My question is, what should I do now? I mean, I obviously don't want user to login again into Facebook and post to wall. I just want user to click a button and story should automatically share on his Facebook wall. How should I do that? Should I pass session object via Intent? Should I start a new session by using the access token saved in the Shared Preference, and how should I do that?

I found so many questions about Facebook SDK 3.0 but none of them could provide me with what I'm looking for. Could anyone please shed some light on it?

2

2 Answers

3
votes

You do not need to explicitly save the access token, or recreate the session with an access token, the SDK already does this for you!

Just use the active session across all activities, and open a new active session if the one you get is null.

The active session is a static inside the Session class, which means that it's preserved across activities, even when they "finish".

The active session will also auto-load the access token if the user has already authorized your app.

1
votes

If the user loged in the first time, a session should be created. I think, as long the session doesn't get closed by the app, the user doesn't have to login again. You can get the active Session with Session.getActiveSession()