Programmatically Publish tweet on Twitter using PHP

Programmatically Publish tweet on Twitter using PHP

  • 14 July, 2018
  • Renish Khunt
  • PHP
  • 124

The Twitter is the most popular social network. Twitter is the best for marketing of your product or blogs article. Twitter is the social network many times we don’t have time to manually publish tweet on time. So let’s how we can Programmatically publish tweet to Twitter using PHP

Let’s see how we can publish tweet on the Twitter platform using PHP programmatically. We used the TwitterOAuth package for publishing tweet on the Twitter. So let’s First installed the TwitterOAuth package on your PHP Application.

composer require abraham/twitteroauth

After, the package was installed let’s start the written code for publishing a tweet.

Publish tweet to Twitter

require "vendor/autoload.php";

use Abraham\TwitterOAuth\TwitterOAuth;

$connection = new TwitterOAuth(

$content = $connection->get("account/verify_credentials");

$tweetPost = $connection->post("statuses/update", ["status" => "Hello, I'm currently feeling Awesome");

if ($connection->getLastHttpCode() == 200) {
    echo "Tweet Published Successfully.";
} else {
    echo "Something went wrong please try again.";

Now let’s create the Twitter app for getting the API key at “”. Then set API key on above PHP Script and replace the status tweet as you want.

Now let’s run the script for publishing tweet programmatically on the Twitter.

write the comment below if you face any issue.