atymic/twitter

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()

  1. composer require atymic/twitter

  2. php artisan vendor:publish --provider="Atymic\Twitter\ServiceProvider\LaravelServiceProvider"

  3. 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']);
}

reliq commented

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:

image


As shown in the readme the postTweet() function is only available for API v1 at this time.