How to properly handle session and access token with Facebook PHP SDK 3.0?

前端 未结 5 1937
不知归路
不知归路 2020-11-30 18:05

In the PHP 3.0 SDK there is no getSession() or any session handling from outside the Facebook api available. Some days ago the developers of facebook have also

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 18:57

    I'm using now PHP SDK 3.x without any problem.

    Naitik the class author removed the getSession() function, and now if you want to know if the user is authenticated or not, use getUser().

    For Access token, it's very simple, use this function getAccessToken(), and you'll get the access token to make Graph or Rest API calls.

    $user = $facebook->getUser();
    
    if ($user) {
    //USER Logged-In
    }
    else {
    //USER not Logged-In
    }
    
    //TO GET ACCESS TOKEN
    $access_token = $facebook->getAccessToken();
    
    
    //MAKE AN API CALL WITH IT
    $user_info = $facebook->api('me?fields=id,name,first_name,last_name&access_token='.$access_token);
    

提交回复
热议问题