Line 4: We start by using the RedirectLoginHelper
(you may be familiar with this from v4.0.x of the SDK). This is needed to generate the login / logout URLs and retrieve the Access Token from Facebook.
Lines 7-20: We check to see if the code has already been provided by Facebook after a login redirect. If we have one, we attempt to get the access_token using the helper (line 12), and then store this in the session (line 15).
Line 23: If we already have an access_token
saved in the session we retrieve it here. The access_token
saved on line 15 is also retrieved here. If the token does not exist, the $access_token variable will be null
.
Line 26: We check if we have an access_token
, and then make sure it hasn't expired.
Line 29: This is a function to set the default access_token for the user, so that all subsequent API calls use that token. If you don't want to set the default token, you can also pass it to requests manually.