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

前端 未结 3 1707
旧巷少年郎
旧巷少年郎 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:34

    Full flow - four page example (easier to edit and understand for an example)

    So the config just has the basic app info...

    When you load index.php - it redirects to facebook to get authorization for the page.. (probably already have this.. but covering all bases)

    Facebook then redirects back to the redirecturl (backfromfb.php)...

    Facebook returns the access token as a hash and not a get variable, so this page refreshes with the hash as a variable...

    It then loads the PageUpdate.php which handles looping through the app/admin tokens and finds the correct one for the page you want to post to..

    Then it builds the post and submits it..

    It sounds like you have an understanding of most of this... So hopefully this will help you with that last bit.

    config.php

     'YOUR APP ID',
        'secret' => 'YOUR APP SECRET',
        'cookie' => true;
        );
    
    $baseurl = 'http://yoursite.com/';
    $returnpage = 'backfromfb.php';
    
    require_once('library/facebook.php');
    
    ?>
    

    index.php

    
    
    Redirecting for auth
    

    backfromfb.php

    
    Redirecting
    
    

    PageUpdate.php

      $_REQUEST['acess_token']
    );
    
    $fb = new Facebook($config);
    
    // Load APP page access rights for user via AppToken
    $pageAdmin = $fb->api('/me/accounts', 'GET', $AppToken);
    
    // Find the page access token
    foreach ($pageAdmin['data'] as $data) {
        if ($data['id'] == $pageID) {
            $pageToken['access_token'] = $data['access_token'];
            continue;
        }
    }
    
    // compile the post
    $WallPost = array(
        'message' => 'Test post from my app!'
    );  // you can also use 'picture', 'link', 'name', 'caption', 'description', 'source'.... 
        //http://developers.facebook.com/docs/reference/api/
    
    
    // post to wall
    $response = $fb->api($pageID . '/feed','POST',$WallPost);
    
    if($response) {
    
        echo 'Success!';
        echo '
    ' . $response . '
    '; } else echo "failed"; ?>

提交回复
热议问题