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();
$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);
//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
));