0

我通过 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_tokenexpires属性,但在下一次请求时我丢失了它们,无论是页面刷新还是导航到另一个页面。

是否有解决方案或替代方法来实现它?我究竟做错了什么?

4

0 回答 0