PHP code example of namest / facebook

1. Go to this page and download the library: Download namest/facebook library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

namest / facebook example snippets


$user = new User(<facebook_id>);
$user->sync(); // Sync all user informations
$user->fetch(); // Get user information from facebook but not sync
$user->get(); // Get user information from local database
$user = User::find(<facebook_id>);
$user = User::findOrSync(<facebook_id>);
$user = User::findOrFetch(<facebook_id>);

$pages = $user->accounts; // Get all user's pages from local database
$user->accounts()->sync(); // Sync user's pages from facebook

$page = $pages[0]; // Return Page instance
$page->sync(); // All object api is the same
$page->posts; // Get all page's posts from local database
$page->posts()->sync(); // Sync page's posts from facebook

// Comment
$user->leave($message)->on($post); // Leave comment
$user->leave($message)->on($comment); // Leave comment

// Like & Unline
$user->like($comment);
$user->like($post);
$user->unlike($comment);

// Hide & Unhide
$user->hide($comment);
$user->unhide($comment);

// Delete
$user->delete($comment);
$user->delete($post);

// Publish
$user->publish($message)->on($page); // Publish Post

// Schedule
$user->schedule($post, $published_at);

$post->page; // Get page of post

$user->accounts

$post->likes
$post->comments

$comment->likes
$comment->comments