PHP code example of hamzahassanm / laravel-social-auto-post

1. Go to this page and download the library: Download hamzahassanm/laravel-social-auto-post 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/ */

    

hamzahassanm / laravel-social-auto-post example snippets


return [
    'facebook_access_token' => env('FACEBOOK_ACCESS_TOKEN'),
    'facebook_page_id'      => env('FACEBOOK_PAGE_ID'),
    'facebook_api_version'  => env('FACEBOOK_API_VERSION', 'v20.0'),
    'telegram_bot_token'    => env('TELEGRAM_BOT_TOKEN'),
    'telegram_chat_id'      => env('TELEGRAM_CHAT_ID'),
    'telegram_api_base_url' => env('TELEGRAM_API_BASE_URL', 'https://api.telegram.org/bot'),
];

use FaceBook;

$caption = 'Check out this article!';
$url = 'https://example.com/post/123';

FaceBook::share($caption, $url);

use FaceBook;

$caption = 'Look at this amazing view!';
$imageUrl = 'https://example.com/images/view.jpg';

FaceBook::shareImage($caption, $imageUrl);

use FaceBook;

$caption = 'Watch this awesome video!';
$videoUrl = 'https://example.com/videos/video.mp4';

FaceBook::shareVideo($caption, $videoUrl);

use FaceBook;

// Fetch insights for page impressions and engagement
$metrics = ['page_impressions', 'page_engaged_users'];
$additionalParams = ['since' => '2024-01-01', 'until' => '2024-01-31'];

$insights = FaceBook::getPageInsights($metrics, $additionalParams);

use FaceBook;

$pageInfo = FaceBook::getPageInfo();

use Telegram;

$caption = 'Check out this article!';
$url = 'https://example.com/post/123';

Telegram::share($caption, $url);

use Telegram;

$caption = 'Here is a cool image!';
$imageUrl = 'https://example.com/images/cool_image.jpg';

Telegram::shareImage($caption, $imageUrl);

use Telegram;

$caption = 'Here is an important document!';
$documentUrl = 'https://example.com/files/document.pdf';

Telegram::shareDocument($caption, $documentUrl);

use Telegram;

$caption = 'Watch this video!';
$videoUrl = 'https://example.com/videos/video.mp4';

Telegram::shareVideo($caption, $videoUrl);

use Telegram;

$updates = Telegram::getUpdates();

try {
    FaceBook::share($caption, $url);
} catch (\Exception $e) {
    \Log::error("Error posting to Facebook: " . $e->getMessage());
}

try {
    Telegram::share($caption, $url);
} catch (\Exception $e) {
    \Log::error("Error posting to Telegram: " . $e->getMessage());
}



return [
    // Other providers
    HamzaHassanM\LaravelSocialAutoPost\SocialShareServiceProvider::class,
];
bash
php artisan vendor:publish --provider="HamzaHassanM\LaravelSocialAutoPost\SocialShareServiceProvider" --tag=autopost