How to Create Tweets Using the Twitter API

I’m going to quickly show you the exact code to send a tweet using the Twitter API. Then, how to learn to build a full-fledged Twitter app.

Let’s dig in.

Before you start, you need three things:

  1. A developer account on Twitter. (dev.twitter.com)
  2. A Twitter app for the API keys and access tokens (apps.twitter.com)
  3. The Twitter OAuth PHP class (twitteroauth.com)

Download the class to your working folder. Then, create a file called index.php (or whatever you want) and include the Twitter OAuth class like so:

require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

Next, we need to connect to the API:

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");

You, of course, need to change out CONSUMER_KEY, CONSUMER_SECRET, $access_token and $access_token_secret with the actual ones from your Twitter app (which is why you need to create one to do this).

Then to get tweets, do this:

$statuses = $connection->get("statuses/home_timeline", ["count" => 25, "exclude_replies" => true]);

This will get your last 25 tweets, excluding replies.

Finally, to create a new tweet, do this:

$statues = $connection->post("statuses/update", ["status" => "hello world"]);

Changing “hello world” to whatever you want to tweet.

That’s it. Pretty damn easy.

Now, if you’d like to see all of this in a video walk-through and learn how to build a full-fledged Twitter client, then grab a copy of the Complete Web Developer Course by Rob Percival 75% off the normal fee here.

In the API section, he covers all of this… plus a Google Maps client… and you’ll build 25 websites and mobile apps throughout the course.

No way you go through this and aren’t ready to take on a full-time IT job.

Anyway, go here to learn all this at 75% off the normal cost: http://johnmorrisonline.com/cwdc

You might also like

Real-world alchemy

Question: what’s a simple way to pandemic proof your business? Or what about the next recession? There’s always one around the corner for one reason

Read More »

$5,857.20

That’s been the top, so far. The highest I’ve hit on Skillshare. And that IS just Skillshare. Doesn’t count Udemy, sales on my own website,

Read More »
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on reddit
Reddit
Share on pinterest
Pinterest
John Morris

JOHN MORRIS

I’m a 15-year veteran of freelance web development. I’ve worked with bestselling authors and average Joe’s next door. These days, I focus on helping other freelancers build their freelance business and their lifestyles.

The simple secrets to high-paying freelance clients

What makes clients willing to pay $5,000, $10,000 even $20,000 and up for your services? Download and install my mobile app and I’ll show you. It’s free. Just click the button below:

Clients Like:

Inc. Magazine Logo
Lewis Howes Logo
Ray Edwards Logo

WHAT OTHERS ARE SAYING

Daniel Mohlendick

On the Freelancing on Upwork course: “This is by far the best course i have watched on Skillshare!! Thank you so much.”

Jim DeJonge

Jim DeJonge

John has a relaxed and engaging manner. His advice is solid and the explanations are well thought out.

Bob Patterson

Not only is John a very talented programmer and developer, he is also an excellent communicator. He has a talent for taking complex subjects and communicating them in terms that anyone can understand. This is a rare combination. This ability has enabled me to take my skills and knowledge to the next level. Thank you John for for all that you do.

Andrew Malone

Andrew Malone

John Morris is exceptional in his ability to give focused insight into Freelancing and starting one’s business. His direct methods inspire confidence in his honesty.

Michael Skye

Michael Skye

John is a man of integrity, who gives generously of himself to projects and people he cares about.

Bradley Smith

John and I have worked together on numerous projects. John is very quick and efficient and was a pleasure to work with.

Jason Rumley

Jason Rumley

John has a habit of over-delivering on the expectations he sets up. That’s why he’s the best.

Sukh Plaha

John is a fantastic and patient tutor, who is not just able to share knowledge and communicate it very effectively – but able to support one in applying it. However, I believe that John has a very rare ability to go further than just imparting knowledge and showing one how to apply it. He is able to innately provoke one’s curiosity when explaining and demonstrating concepts, to the extent that one can explore and unravel their own learning journey. Thanks very much John!

Lewis Howes

John is amazing at building membership sites. He converted one of my sites over from it’s existing (hardly working) platform over to the clean and simple to use WishList membership platform. I highly recommend using John and WishList for any of your membership site needs.

Aaron Gott

Aaron Gott

John has a particular knack for the development and training of others.

Chris Aitken

He significantly improved my site through his expert knowledge of PHP, CSS and Javascript. Would definitely recommend John to others.

Lori Grant

John did an outstanding job on my project. I highly recommend him and look forward to working with him on future projects.

Ray Edwards

I recommend John every chance I get. If every person I worked with were as committed to excellence, punctuality, value, and unquestionable integrity… the world would be a better place. Highest recommendation.