facebook api blank response and no exception

梦想与她 提交于 2019-12-25 06:43:34

问题


 $facebook = new Facebook(array(
                'appId'  =>Yii::app()->params['FBappId'],
                'secret' =>Yii::app()->params['secret'] ,
                ));

                // Get User ID
                $user = $facebook->getUser();
              if ($user) {
              try {
                // Proceed knowing you have a logged in user who's authenticated.
                echo $accessToken=$facebook->getAccessToken();
                echo '<br/>';
                $user_profile = $facebook->api('/me');
                print_r($user_profile); echo "normal sdk"; exit;
              } catch (FacebookApiException $e) {
                  echo $e; exit;
                $user = null;
              }
            }
            echo "normal sdk end";exit;

i tried with php sdk 3.3.2 and user login by facebook it prints the token and user info untill token expire. after about one hour i check by token debugger session expired and it give exception once and then blank response.but in another tab facebook is being accessed . my question is

1.When token expired, is there any inbuild method to get valid token again ?

2.Why blank response? everytime it should throw exception


回答1:


You can use Facebook's Debug Tool to check the validity of your access token.

The normal access token expires in 2 hours, and the extended token lasts for 2 months.

If you want the extended token, go though this: How to extend access token validity since offline_access deprecation

Well, If you are getting blank for $facebook->api('/me'); this simply means that the user have not authorized the app yet. Try something like this-

$user_id = $facebook->getUser();
echo $uid;

if($user_id){
  try {
    $user_profile = $facebook->api('/me');

  } catch (FacebookApiException $e) {
    error_log($e);
    $user_id = null;
  }
}else{
    $login_url = $facebook->getLoginUrl();
    echo("<br>login url=".$login_url);
};


来源:https://stackoverflow.com/questions/13821716/facebook-api-blank-response-and-no-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!