PHP code example of abhishekbhardwaj / twitter-api-php

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

    

abhishekbhardwaj / twitter-api-php example snippets


$credentials = new AppCredentials($consumerKey, $consumerSecret);

$client = new Client($credentials);

$app = $client->connect();

$app->createBearerToken();

//to access bearer token (for storing in db for later use), you can use:
$app->getCredentials()->getBearerToken();

//getting @abhishekwebin's recent timeline.
$response = $app->get('users/show.json', array('screen_name' => 'abhishekwebin'));

$response->getHeaders(); //gets the response headers
$response->getStatusCode(); //gets the status code
$response->json(); //parse response as JSON and return decoded data as assoc-array
$response->getBody(); //gets the response body

$credentials = new UserCredentials($consumerKey, $consumerSecret, $callbackUrl);

$client = new Client($credentials);

$app = $client->connect();

$redirectUrl = $app->getRedirectUrlForAuth();

$accessTokens = $app->getAccessToken($oauthToken, $oauthVerifier);

//getting @abhishekwebin's recent timeline.
$response = $app->get('users/show.json', array('screen_name' => 'abhishekwebin'));

//post a new tweet: 'Test status!' as the currently authenticated users.
$response = $app->post('statuses/update.json', array('status' => 'Test status!'));

//list of pictures to upload. Input array items shouldn't be more than 4.
$media = $app->uploadMedia(array(
    '{{FULL PATH TO PICTURE}}',
    '{{FULL PATH TO PICTURE}}',
    '{{FULL PATH TO PICTURE}}',
    '{{FULL PATH TO PICTURE}}'
));

//post a new status
$response = $app->post('statuses/update.json', array(
    'status' => 'Test status!',
    'media_ids' => $media
));

    {
        "bhishekbhardwaj/twitter-api-php": "~1.1"
        }
    }

"php": ">=5.4.0",
"guzzlehttp/guzzle": "~5.0",
"guzzlehttp/oauth-subscriber": "~0.2"