Combination of API V1 and V2 for PHP with CURL instead of any other libraries, this is a pacjage that provides an easy and fast integration of Twitter.
For now, it's not possible to upload files with API V2, that's why it's a combination of them.
First you need to add the component to you composer.json.
composer require cleytonbonamigo/twitter-share
Firstly, you need to follow this tutorial.
- Request of an approved account;
- Once you have an approved developer account, you will need to create a Project;
- Enable read/write access for your Twitter app;
- Generate Consumer Keys and Authentication Tokens;
- Grab your Keys and Tokens from the twitter developer site.
Settings are expected as below:
use CleytonBonamigo\ShareTwitter\Client;
$settings = [
'access_token' => access_token,
'access_token' => access_token,
'access_token_secret' => access_token_secret,
'consumer_key' => consumer_key,
'consumer_secret' => consumer_secret
];
$client = new Client($settings);
$url = ''; //An URL or path to local file
$return = $client->media()->uploadMediaFromUrl($url);
$tweet = [
'text' => 'Text of your tweet :)',
'media' => [ //This param is optional
'media_ids' => [
'media_id_string' //Returned at uploadMediaFromUrl()
]
]
];
$client->tweet()->create(['text' => 'Test new tweet post with image complete flux', 'media' => ['media_ids' => [$media->media_id_string]]]);
Fork/download the code and run.
composer install
Copy test/config/.env.example
to test/config/.env
and add your credentials for testing.
./vendor/bin/phpunit
or composer test
.