Codegena

Analyze your Twitter handle with IBM application

Twitter is an American online platform and social networking site on which users can post and interact with messaged which are called as tweets. You can, of course, connect to people you know, and you can also connect with strangers who have similar interests as yours across the world.

Twitter plays a major role in the marketing of different businesses. The web only business having revenue only through advertisements are the most benefited. Other companies including B2B and B2C can spread its product information on twitter and can get majorly benefited by reaching out to a major population. Twitter has also been used extensively in the field of education. You can get access to multiple links and information.

Twitter analytics provides huge information that can help you create sensible tweets that will be useful for your target audience. It helps you to understand the insights of audiences including interests, education, marital status, buying style etc. Your twitter followers should be your correct target audience and twitter analytics will help you understand that better.

With the comparison data, you can compare your followers with different factors like demographics, interests and consumer behaviour.

Tweet impressions help you find the list of all your tweets and impressions. You can in fact see your individual tweet performance and a recent month performance. The engagement rate on tweets helps you understand the number of interactions you have on your tweet. You can also track your following rate in the follower’s dashboard.

There are many ways to deploy a Java application, even when deploying to a specific cloud provider, there are various ways to deploy any application. By leveraging an Eclipse plug-in, this tutorial will demonstrate how quick and effortless it is to deploy a Java application to IBM Cloud in just a few clicks.

The application in this guide will prompt the user to enter a Twitter handle and then calculate how influential that Twitter handle is by running an analysis of their account. It will also return other data such as the number of followers, a follower score, a retweet count, a retweet score, and the number of recent mentions. A list of the accounts most recently ten tweets is also displayed. If geolocation data is available for the tweets, then it is plotted and shown on Google Maps. Upon viewing the results, you can save the data to a database to store the account name and statistics summary. The contents of the database can be viewed from the home page of the application.

Also Read: 5 must know tips to increase your tweet engagement

Prerequisites

In order to use this how-to, the reader will need the following prerequisites:

Steps

Install the IBM Bluemix Plug-in

Note: This plug-in will be renamed in the future from Bluemix to IBM Cloud.
To install the IBM Bluemix plug-in for Eclipse, launch Eclipse and follow the instructions below:

  1. Click the Help menu, and the Eclipse Marketplace submenu.
  2. Search for “Bluemix”.
  3. Install the plug-in named “IBM Eclipse Tools for Bluemix”.

Import the WAR file into Eclipse

To import the WAR file to Eclipse follow the instructions below:

  1. Navigate to the releases page of the bluemix-java-sample-twitter-influence-app application on Github.
  2. Find the “Latest release” tag and click the bluemix-java-twitter-influence- analyzer.warfile to start the download.
  3. From Eclipse, click the File menu, and the Import submenu.
  4. Scroll down to the Web section, expand that section, click WAR File, and click Next.
  5. Locate the local WAR file. Ensure the Target Runtime is set to IBM Bluemix.
  6. Click Next and then Finish. The project should be imported into your Eclipse workspace.

Generating Twitter and Google Maps API keys

This application uses some Twitter and Google Maps APIs, so we will need to register our application and generate a few API keys and tokens.

The sample application will not work if the Twitter API keys and tokens are not set as environment variables.

Twitter API

To access the Twitter API we will need to create a consumer key and secret as well as a access token key and secret. To do so we must register our application with Twitter.

  1. Navigate to Twitter Application Management
  2. Sign into your twitter account and click on Create New App, fill out the form.

When configuring your twitter application, it will ask for the fully-qualified URL to the website. This should match, exactly, the URL you plan to use on IBM Cloud. For example, if your IBM Cloud app will be located at https://twitter-influence-analyzer.eu-gb.mybluemix.net, then the Website text box should read that exact URL.

  1. After registering the app any API keys and token can be viewed under the Keys and AccessTokens tab.
  1. To get your API access token, click Create my access token at the bottom of the page and you will see the generated access token and access token secret.
  1. Be sure to jot down or copy the values for: Consumer Key (API Key), Consumer Secret (API Secret), Access Token, and Access Token Secret as we will need them soon.

Google Maps API

The sample application also uses the Google Maps v3 APIs. Google Maps APIs are open for developers and it is not necessary to register the application with Google. Navigate to the Google Maps API and select the GET A KEY button to create a new API key.

Deploying the application

Configure the Bluemix plug-in

Ensure you are in the Java EE perspective in Eclipse.

  1. In the bottom window section, select the Servers tab. Alternatively, you can click Window > Show View > Servers.
  2. Right click inside the Servers panel and select New, then Server.
  3. Select the IBM menu, then the IBM Bluemix submenu, click Next.
  4. Enter your login information for IBM Cloud in the email and password sections.
  5. From the URL dropdown menu choose IBM Bluemix
  6. Click Next. IBM Cloud will automatically validate your account credentials.
  7. Optional: Select the organization within your IBM Cloud account that you would like to deploy to.
  8. Click: Finish

Push the application

  1. Right click on the Bluemix server and click: Connect.
  2. Right click on the Bluemix server and select: Add and Remove….
  3. Select your Twitter Influence Analyzer project from the window on the left and click: Add.
  4. Enter a name for your app and select: Next.
  5. Enter the same subdomain that you used to register with Twitter. (e.g. https://twitter-influence-analyzer.eu-gb.mybluemix.net) click Next.
  1. Select the Add a service icon in the top right. Note that it the yellow icon.
  1. Search for cloudantNoSQLDB, and select the first option. Give it a name and select the Lite plan.
  2. Select Finish. This will create a free Cloudant service in your IBM Cloud organization. Click Next.
  1. Lastly, right click the application and select Environment Variables. Here we will add your Twitter API credentials as environment variables to the application runtime. Select New for each environment variables, they will be added one by one:

| Environment Variable Name | Value                                |

|—————————|————————————–|

| TWITTER_CONSUMER_KEY      | `{Your Twitter API Key}`             |

| TWITTER_CONSUMER_SECRET   | `{Your Twitter API Secret}`          |

| TWITTER_ACCESS_TOKEN      | `{Your Twitter Access Token}`        |

| TWITTER_ACCESS_KEY        | `{Your Twitter Access Token Secret}` |

Note that you may do this step later, but your application will fail without it. Click Finish, the application will now deploy to IBM Cloud. You may now push the application using the Start or Pushbutton in Application Operations section shown below:

Congratulations! The application is now published to IBM Cloud! You may now view your app by copying and pasting the URL shown in the section below to your browser:

Using the application

Below is the home screen of the app. You can enter a Twitter handle in the text box and click the Analyze! button to see their influence. You can also view any records saved in the database by clicking on the View Database button.

After analyzing a Twitter handle you’ll be able to see the influence analysis and their ten most recent tweets (plotted in Google Maps if geolocation is enabled for a tweet).


Shan Eapen Koshy

Shan Eapen Koshy is a web developer, technical blogger and a YouTuber. He has created several web applications and has written many app scripts.

Follow Us

Don't be shy, get in touch. We love meeting interesting people and making new friends.