Facebook API: How to publish to Page feed while user is offline without offline_access permission

前端 未结 3 1658
旧巷少年郎
旧巷少年郎 2021-02-02 00:01

Using Facebook\'s Graph API, I\'ve been successful at publishing to a user\'s feed while the user is offline with only the publish_stream permission. I don\'t need the offline_

3条回答
  •  盖世英雄少女心
    2021-02-02 00:08

    The problem is you need to use the access token for the page provided via the premissions gained...

    Uh... Easier way to say it is this:

    Your app requested premission to "manage_pages" - once you accept/grant premission then you have an access_token for the apps premission (offline would just make expires=0 here)

    So now your app has premission to manage your pages, but it needs the token for the specific page...

    So if you issue a /me/accounts (or /UID/accounts) with the first token you will get a list of the pages the application has premission to access and their respective tokens...

    From there just grab the token of the page and then issue your command with that token

    Using the facebook class (facebook.php and cert file)

    require_once 'library/facebook.php';
    
    $app_id = "YOURAPPID";
    $app_secret = "YOURSECRET";
    
    $facebook = new Facebook(array(
        'appId' => $app_id,
        'secret' => $app_secret,
        'cookie' => true
    ));
    
    $token =  array(
        'access_token' => 'THE Token from app / manage_page auth'
    );
    
    $userdata = $facebook->api('/me/accounts', 'GET', $token);
    
    echo ';
    print_r($userdata);
    echo '
    ';

    You should see a llist of page id's and their access tokens...

    Usuually i do a foreach $userdata['data'] and look for the page id, then i grab the token from that subarray...

提交回复
热议问题