Session Key & Access Token in Facebook-API

2020-07-17 06:41发布

问题:

Can someone please explain to me once and for good what are Session Key & Access Token? How do I catch those two? Why and when do I need to use them? When it is 'one-time' and when it is not?

Also, what are the differences between them. Please do it in Java. I'm a new-to-facebook-API Java developer who's trying to get his application to work with Facebook.

This is my basic code so far:

FacebookJsonRestClient client = new FacebookJsonRestClient(API_KEY, SECRET);
HtmlDisplay HD = new HtmlDisplay("http://www.facebook.com/login.php?api_key=1668a3eee255c05918c4234bc4371beb&connect_display=popup&v=1.0&next=http://www.walla.co.il&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&session_key_only=true&req_perms=user_photos,publish_stream,offline_access");
hd.popUp();
client.auth_getSession(token, true);
System.out.println(client.getCacheSessionKey());

I also tried to put

&auth_token=TOKEN

inside HD and get it with

CLIENT.auth_createToken();

Nothing works. Thanks

回答1:

Session key and access token are two mutually exclusive concepts. Session key was used in old REST API, access token is used in new OAuth and Graph API.

The java library you are using supports only old REST API and pretty outdated. I would suggest switching to Graph API java library, like RestFB.

Authorization process for OAuth is described in details here. You would also find a lot of examples on RestFB page.