1. Go to this page and download the library: Download siberfx/facebook-autopost 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/ */
siberfx / facebook-autopost example snippets
use App\Models\User;
use Illuminate\Support\Facades\Gate;
Gate::define('manage-facebook-autopost', fn (User $user) => $user->is_admin);
use Siberfx\FacebookAutopost\Facades\Facebook;
if (Facebook::isConnected()) {
$connection = Facebook::connection();
$connection->name; // "Siberfx Page"
$connection->pageId; // "1234567890"
$connection->status; // active | expired | unknown
$connection->expiresAt; // CarbonImmutable|null (null: the token does not expire)
$connection->toArray(); // everything above as an array, never the token
}
use Illuminate\Support\Str;
use Siberfx\FacebookAutopost\Concerns\PostsToFacebook;
use Siberfx\FacebookAutopost\Contracts\ShareableOnFacebook;
use Siberfx\FacebookAutopost\Posts\FacebookPost;
class Article extends Model implements ShareableOnFacebook
{
use PostsToFacebook;
public function isLiveForFacebook(): bool
{
return $this->status === 'published';
}
public function toFacebookPost(): FacebookPost
{
return FacebookPost::make(url: route('blog.show', $this), title: $this->title)
->commentary("New on the blog: {title}\n\n{url}");
}
}
use Siberfx\FacebookAutopost\Facades\Facebook;
Facebook::share($article); // now; returns the FacebookShare record (re-sharing is allowed)
Facebook::queue($article); // in the background
Facebook::wasPosted($article); // bool, same as $article->wasPostedToFacebook()
$article->facebookShares; // history: post_id, status, trigger, error, posted_at