1--- tags: [] projects: [spring-social-twitter] --- :toc: :icons: font :source-highlighter: prettify :project_id: gs-register-twitter-app

This guide walks you through the steps of registering an application that you can integrate with Twitter. Registering the application is the first step in developing an application that is integrated into its users' social graph.

You perform the steps in this guide in your web browser on Twitter.com. Although you won’t be writing any code, you’ll use a simple utility project to verify that you performed the steps correctly. Instructions for getting and running the utility are at the end of this guide.

Register a new application

All Twitter users are potentially Twitter application developers. Simply visit http://dev.twitter.com and sign in with your Twitter credentials.

Go to https://apps.twitter.com/ to see a page that will list all your Twitter applications, once you create them. If you haven’t created any applications yet, the list is empty.

Click the tw new app button button near the top. A new page with the Create an application form requires basic information about your application.

tw create app

In the Name field, name your application in 32 characters or fewer. This name is presented to users when they are prompted to authorize your application to access their Twitter information. In the Description field, describe your application in 10 to 200 characters. Again, this is presented to users on authorization screens.

In the Website field, give a URL that points the user back to your application, where they can download it or find out more information. As with Name and Description, this field is presented on user-facing authorization screens.

The Callback URL field can specify the URL were Twitter should redirect after a successful authorization. You can leave this blank to complete the exercise in this guide, but in general you will want this to be a valid URL (even though Twitter allows you to change it at runtime).

The developer Rules Of The Road section outlines rules you must agree to follow if you build an application that uses Twitter’s API.

tw rules of road

The rules include style guidelines on how to present tweets and cautions against simply recreating the functionality of Twitter’s own clients. It is recommended that you read these rules closely to make sure you don’t violate them.

If you agree to the rules, check "Yes, I agree".

A Captcha challenge ensures that you’re not setting up applications through an automated process.

tw captcha

Click "Create your Twitter application" to complete the form and go to the application settings page.

tw app details

Here you configure details about your application, according to what kind of application you plan to build and what you want it to do.

The main fields to note are Consumer key and Consumer secret. These values are your application’s credentials for Twitter.You need them to do almost anything with Twitter, including going through the OAuth authorization flow and working with Twitter’s REST API.

Verify the registration

Now you can use your consumer key and secret to access Twitter’s API. The sample utility application in GitHub is an example of an application that can use the consumer key and secret to search Twitter.

You can clone the utility project from GitHub:

git clone https://github.com/spring-guides/{project_id}.git

To run the utility, simply run it from the command line using Gradle like this:

./gradlew clean build && java -jar build/libs/{project_id}-0.1.0.jar

Or if you are using Maven, run it like this:

mvn package && java -jar target/{project_id}-0.1.0.jar

You can alternatively run the app directly from Gradle like this:

./gradlew bootRun
With mvn, you can run mvn spring-boot:run.

You’ll be prompted by two dialogs. The first will ask for the application’s Consumer ID and the second will ask for the application’s Consumer Secret. Copy and paste the values from the Twitter Developer’s site.

The application then queries Twitter’s REST API, searching for Tweets that have "#springframework" in the text. If you’ve set your application up correctly, you should see the text of several matching Tweets.


Congratulations! You have now registered an application with Twitter.

See Also

The following guides may also be helpful:

Want to write a new guide or contribute to an existing one? Check out our contribution guidelines.

All guides are released with an ASLv2 license for the code, and an Attribution, NoDerivatives creative commons license for the writing.