PHP code example of laminas / laminas-twitter

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

    

laminas / laminas-twitter example snippets


use Laminas\Twitter\Twitter;

$twitter = new Twitter([
    'access_token' => [
        'token' => '<token value>',
        'secret' => '<token secret value>',
    ],
    'oauth_options' => [
        'consumerKey' => '<consumer key value>',
        'consumerSecret' => '<consumer secret value>',
    ],
]);

$twitter->users->lookup($id, array $params = []);
$twitter->users->search(string $query, array $options = []);
$twitter->users->show($id);

public function get(string $path, array $query = []) : Response;
public function post(string $path, $data = null) : Response;

$image = new Image('data/logo.png', 'image/png');
$response = $image->upload($twitter->getHttpClient());

$twitter->statusUpdate(
    'A post with an image',
    null,
    ['media_ids' => [$response->media_id]]
);

$image = new Image(
    'data/logo.png',
    'image/png',
    $forDirectMessage = true,
    $shared = false
);
$upload = $image->upload($twitter->getHttpClient());

$twitter->directmessagesEventsNew(
    $user,
    $message,
    ['media_id' => $upload->id_str]
);

$response = $twitter->statusUpdate('A post');
$rateLimit = $response->getRateLimit();
if ($rateLimit->remaining === 0) {
    // Time to back off!
    sleep($rateLimit->reset); // seconds left until reset
}