从未使用2016 Facebook API过期页面令牌? [重复]

This question already has an answer here:

I am currently working on an app that connects high school students with nonprofits to help manage their social media pages and gain community service hours.

We give each student a social impact score calculated by the amount of likes, comments, shares that are garnered by their posts for the foundations. We are trying to create a server that pulls data from these Facebook pages with a never-expiring Page Access Token. Does this require a login script if we try to retrieve data on an ongoing basis? Also, our code below keeps showing an error.

What is wrong with it?

<?php
    // Defining FB SDK with absolute paths
    define('FACEBOOK_SDK_V4_SRC_DIR', 'http://www.website.com/src/Facebook/');
    require 'http://www.website.com/src/Facebook/autoload.php';

    use Facebook\FacebookSession;
    use Facebook\FacebookRequest;
    use Facebook\GraphUser;
    use Facebook\FacebookRequestException;

    FacebookSession::setDefaultApplication(‘App ID’,’App Secret’);

    $session = new FacebookSession(‘Never expiring page access token’);

    try {
        $data = (new FacebookRequest(
                    $session, 'GET', '/1503911716546178/posts'
                ))->execute()->getGraphObject()->getPropertyAsArray("data");

        foreach ($data as $post){
            $postId = $post->getProperty('id');
            $postMessage = $post->getProperty('message');
            print "$postId - $postMessage <br />";
        }
    } catch (FacebookRequestException $e) {
    // The Graph API returned an error
    } catch (\Exception $e) {
    // Some other error occurred
    }
?>
</div>

Of course you need a login script to get a Page Token, but that would only be a one time thing. After getting the Extended Page Token, you can store it in a database and use it without user interaction.

More information about Tokens and how to generate them:

I suggest using the JavaScript SDK for login, it´s a lot easier to handle than the PHP SDK and the usability is better (no redirection). For example: http://www.devils-heaven.com/facebook-javascript-sdk-login/

About your code: hard to say without the actual error message, but there is no App ID or Secret, and there is no Token (DO NOT POST YOUR SECRET OR ANY TOKEN ON STACKOVERFLOW). Make sure you are using a valid Token, you can test it in the debugger: https://developers.facebook.com/tools/debug/