Reputation: 1490
In Facebook PHP SDK 4.0 you can get a LongLivedSession for a user and get the access token for it. With this token you have access to the users account for more than just a few hours.
$session = new FacebookSession("[normal access token]");
$longLivedSession = $session->getLongLivedSession("[appID]", "[appSecret]");
$longLivedAccessToken = $longLivedSession->getToken();
Facebook\FacebookSession was removed after 4.0 and I need features from the class Facebook\Facebook which was added in 5.0. Right now I can't find a way to get a longLivedAccesToken in 5.0. Is this because I'm looking for something which doesn't exist or is there a way to do this in 5.0?
As a workaround I would use one controller with 4.0 and one with 5.0 in my app, but it would be really nice if I could avoid that, because that would be really messy.
Upvotes: 0
Views: 353
Reputation: 96325
That has been moved to the Facebook\Authentication\OAuth2Client
class now.
If you look at the source code of that class, beginning with line #169 you’ll find:
169 /**
170 * Exchanges a short-lived access token with a long-lived access token.
171 *
172 * @param AccessToken|string $accessToken
173 *
174 * @return AccessToken
175 *
176 * @throws FacebookSDKException
177 */
178 public function getLongLivedAccessToken($accessToken)
179 {
(The documentation does not seem to be fully up to date right now, so in situations like this it is always recommendable that you have a little look around in the source code yourself to see what methods are available and what parameters they take.)
Upvotes: 2