简体   繁体   中英

How to get access Token of active Session with simple Facebook?

I am using library SimpleFacebook and I need to get accessToken of current session. In standard fb sdk it looks like this:

Session session = Session.getActiveSession();
@Override
public void onCompleted(GraphUser user, Response response) {
                    String accessToken = session.getAccessToken();
}

but how to get this string with library SimpleFacebook?

Try this :

SimpleFacebook mSimpleFacebook;
mSimpleFacebook=SimpleFacebook.getInstance(this);

Session session=mSimpleFacebook.getSession();
AccessToken accessToken=session.getAccessToken();

In the onResume() Method of your code you can use this :

 Session session = Session.getActiveSession();
 String token = session.getAccessToken()

or you can even use this(Note : This is applicable only After Facebook SDK version 4.X)

AccessToken token = AccessToken.getCurrentAccessToken(); 

To access the accessToken as a String you actually need to use String accessToken = mSimpleFacebook.getAccessToken().getToken()

So if you change your code to the following it should work:

Session session = Session.getActiveSession();
@Override
public void onCompleted(GraphUser user, Response response) {
                    String accessToken = session.getAccessToken().getToken();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM