A Guide To Twurl and the Twitter API

A Guide To Twurl and the Twitter API

If you’re a developer, chances are that you’ve used the Twitter API once or twice. If not, that’s ok because that is what this article is about. As someone who had very little knowlege of anything code related, getting started with the Twitter API was tough. Questions were asked, people were probably annoyed… Eventually, I familiarized myself by experimenting and playing around.

Understanding the API is fairly simple. When you send a request, Twitter returns data using JSON. To make things a bit more simple, Twitter also has an OAuth-enabled curl tailored specifically to the Twitter API. They call it Twurl. Twurl makes it easy to authorize an account and make requests. It also gives you the ability to swap between access tokens and accounts (which I do frequently).

Installing Twurl

Mac

Windows

Now that Twurl is installed on your system, here is a list of command options that are available to you when using Twurl 👇

Before you get started with the Twitter API, you will want to create and authorize an application. Go to apps.twitter.com to create an app with the permissions that you want. Take note of the access token and access secret. You will need those keys when authorizing.

Now that you have authorized an application to an account, you can familiarize yourself with some of the docs (if you really need to…)

It’s necessary to include -X and to specify your request method (GET, by default, or POST). -H is equally important because that is the command needed to specify the host URL. The Twitter Developer Docs should help greatly as they tell you which method is used. Examples and parameters are also listed there too.

Use #1: Sending a Tweet

Lets say that I want to send out a Tweet with the text “Hello! This Tweet was sent via the Twitter API.” I would look at the Docs and find the POST statuses/update API Reference. Knowing a little bit about how twurl requests look, I simply convert the given JSON request to Twurl.

Be sure to look at the available parameters. You can make your Tweet nullcast (invisible on the public timeline), you can add media or add a Card, etc.

Here is an example with in_reply_to_status_id, media_ids, and the nullcast parameters.

Request

Response

Use Case #2: Creatives

Note: Building Creatives through the Twitter API requires you to have an Ads Account as well as Ads API Access.

If you have Twitter Ads API Access, you are able to create Creatives through the API. Not all creatives are avalable for anyone to create. Some are in beta, some require whitelisting, and some aren’t even public yet.

First, let’s create a Card that is available to everyone (with Ads API acces). A simple Website Card that points towards the Twitter Developers website.

Visit the POST accounts/:account_id/cards/website and view the example and parameters.

Request

Response

Take note of the provided card_uri. We will need that when adding the card to a Tweet.

Composing a Tweet with the Website Card Attached

Next, lets create a Conversation Card with two CTAs. These cards require whitelisting, so if you want access, send a DM to @TwitterAdsHelp.

First, visit the POST accounts/:account_id/cards/image_conversation reference and check out what you can do with the additional parameters.

Request

Response

Again, keep note of the card_uri.

Add the Conversation Card to a Tweet

Request

Response

Hopefully, this article gave you a bit of an insight into the Twitter API. Now that you know how Twurl and the API works, go compose some Tweets or build something cool!

“A Guide To Twurl and the Twitter API” Posted first on ” Coding on Medium “
Author: Sam Schmir

Author: Pawan Kumar

Leave a Reply

Close Menu
%d bloggers like this:
Skip to toolbar