facebook访问令牌随机过期

时间:2013-01-06 14:35:20

标签: php facebook codeigniter facebook-graph-api

我通过Javascript登录,我使用下面的方法检查facebook cookie并从中提取signed_request:

function get_facebook_cookie($app_id, $app_secret) {
        $access_token = null;
        $expires = null;

        $signed_request = (isset($_COOKIE['fbsr_' . $app_id])) ? $this->parse_signed_request($_COOKIE['fbsr_' . $app_id], $app_secret) : NULL;

        if (!is_null($signed_request)) {
            $url = "https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&redirect_uri=&client_secret=".$app_secret."&code=$signed_request[code]";

            $access_token_response = $this->getDataFromUrl($url);           
            parse_str($access_token_response);
            $signed_request["access_token"] = $access_token;

            if($expires == 0){ $signed_request["expires"] = 0; }else{ $signed_request["expires"] = time() + $expires; }
        }
        return $signed_request;
    }

getDataFromUrl()函数:

function getDataFromUrl($url) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }

在第一次回复时,我成功获得 access_token 过期属性,但我在下次请求时丢失了它们,无论是页面刷新还是导航到其他页面。

是否有解决方案或其他方法来实现它?我做错了什么?

0 个答案:

没有答案