PHP code example of ostapovich / facebook

1. Go to this page and download the library: Download ostapovich/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/ */

    

ostapovich / facebook example snippets


use Ostapovich\Facebook;

$facebook = new Facebook('YOUR_FACEBOOK_ACCESS_TOKEN');

$data = ['hub_challenge' => 'CHALLENGE_STRING'];
$result = $facebook->setWebhook($data);

$data = [
    'hub_mode' => 'subscribe',
    'hub_verify_token' => 'VERIFY_TOKEN',
    'hub_challenge' => 'CHALLENGE_STRING'
];
$result = $facebook->setSecurityWebhook($data, 'VERIFY_TOKEN');

$data = [
    'entry' => [
        [
            'messaging' => [
                [
                    'message' => [
                        'text' => 'Hello, world!'
                    ]
                ]
            ]
        ]
    ]
];
$result = $facebook->getMessage($data);

$data = [
    'entry' => [
        [
            'messaging' => [
                [
                    'postback' => [
                        'referral' => [
                            'ref' => 'REFERRAL_DATA'
                        ]
                    ]
                ]
            ]
        ]
    ]
];
$result = $facebook->getRefData($data);

$facebook->setStartButton();

$data = [
    'entry' => [
        [
            'messaging' => [
                [
                    'sender' => [
                        'id' => '123456789'
                    ]
                ]
            ]
        ]
    ]
];
$result = $facebook->getFacebookUserId($data);

$response = $facebook->sendFacebookMessage('USER_ID', 'Hello, Facebook user!');

$bot_url = 'https://m.me/your_bot';
$ref_data = 'REF_DATA';
$deep_link = $facebook->getDeepLink($bot_url, $ref_data);