PHP code example of dg / twitter-php

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

    

dg / twitter-php example snippets


use DG\Twitter\Twitter;

$twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);

$twitter->send('I am fine today.');

$statuses = $twitter->load(Twitter::ME);

$statuses = $twitter->load(Twitter::ME_AND_FRIENDS);

$statuses = $twitter->load(Twitter::REPLIES);

foreach ($statuses as $status) {
	echo "message: ", Twitter::clickable($status);
	echo "posted at " , $status->created_at;
	echo "posted by " , $status->user->name;
}

if (!$twitter->authenticate()) {
	die('Invalid name or password');
}

$results = $twitter->search('#nette');

try {
	$statuses = $twitter->load(Twitter::ME);
} catch (DG\Twitter\Exception $e) {
	echo "Error: ", $e->getMessage();
}

if (!$twitter->authenticate()) {
	die('Invalid name or password');
}

$statuses = $twitter->request('statuses/retweets_of_me', 'GET', ['count' => 20]);