图表返回错误:使用facebook sdk 5.0在API参数中提供的appsecret_proof无效

时间:2017-03-29 08:36:15

标签: facebook facebook-graph-api

我正在使用facebook sdk 5.0。当我运行此代码错误,如“API参数中提供的无效appsecret_proof”。我怎样才能为此配置appsecret_proof。什么是appsecret_proof?请帮我..! :-(

session_start();
    $_SESSION['facebook_access_token'] = '*************************';
    require_once './sdk/src/Facebook/autoload.php';
    $fb = new Facebook\Facebook([
        'app_id' => '**********',
        'app_secret' => '************',
        'default_graph_version' => 'v2.8',
    ]);
    $helper = $fb->getRedirectLoginHelper();
    $permissions = ['email']; // optional

    try {
        if (isset($_SESSION['facebook_access_token'])) {
            $accessToken = $_SESSION['facebook_access_token'];
        } else {
            $accessToken = $helper->getAccessToken();
        }
    } catch (Facebook\Exceptions\FacebookResponseException $e) {
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
    if (isset($accessToken)) {
        if (isset($_SESSION['facebook_access_token'])) {
            $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
        } else {
            $_SESSION['facebook_access_token'] = (string) $accessToken;
            $oAuth2Client = $fb->getOAuth2Client();
            $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
            $_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
            $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
        }
        if (isset($_GET['code'])) {
            header('Location: ./');
        }
        try {
            $profile_request = $fb->get('/me?fields=name,first_name,last_name,email', $accessToken);
            $profile = $profile_request->getGraphNode()->asArray();
        } catch (Facebook\Exceptions\FacebookResponseException $e) {
            echo 'Graph returned an error: ' . $e->getMessage();
            session_destroy();
            exit;
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
            echo 'Facebook SDK returned an error: ' . $e->getMessage();
            exit;
        }
        echo $profile_request->getGraphUser()->getName();
    }

0 个答案:

没有答案