twitter postTwitter method doesn't work in laravel 9
DavidAmirKham opened this issue · 1 comments
I configured the following steps but make error postTweet method of laravel 9.
Error: Call to undefined method Atymic\Twitter\Service\Accessor::postTweet()
-
composer require atymic/twitter
-
php artisan vendor:publish --provider="Atymic\Twitter\ServiceProvider\LaravelServiceProvider"
-
php artisan vendor:publish --provider="Atymic\Twitter\ServiceProvider\LaravelServiceProvider"
use Atymic\Twitter\Facade\Twitter;
public function tweet()
Twitter::postTweet(['status' => 'Laravel is beautiful', 'response_format' => 'json']);
}
Hi @DavidAmirKham. The postTweet
method is not currently explicitly implemented for Twitter API v2.
You can however still post a tweet with API v2 in the following way:
// ...
use Atymic\Twitter\Contract\Http\Client;
// ...
$querier = Twitter::forApiV2()->getQuerier();
$result = $querier->post(
'tweets',
[
Client::KEY_REQUEST_FORMAT => Client::REQUEST_FORMAT_JSON,
'text' => 'my tweet'
]
);
// ...
NB. call to forApiV2()
is optional.
$result
will contain the posted tweet:
As shown in the readme the postTweet()
function is only available for API v1 at this time.