1 of 27

Twitter

BOTs and APIS

SJU ACM STUDENT CHAPTER

Sign In Form:

2 of 27

The Basics of APIs

3 of 27

What is AN API?

  • API: Application Programming Interface
  • Amazon Web Services (AWS) defines API as:
    • “...mechanisms that enable two software components to communicate with each other using a set of definitions and protocols.”
  • Example of how an API works:
    • The weather bureau’s software system contains daily weather data. The weather app on your phone “talks” to this system via APIs and shows you daily weather updates on your phone.

4 of 27

Simplified EXAMple of how an api works

5 of 27

How do APIs work? (Part 1)

  • apis ARE USUALLY TALKED ABOUT IN TERMS OF CLIENT AND SERVER.
    • Application sending the request is the client
    • Application sending the response is called the server
  • Example:
    • In the weather example, the weather bureau’s database is the server, and the mobile app (I.e. The weather channel/Weather app on your phone) is the client.
  • APi endpoints:
    • a point at which an API - the code that allows two software programs to communicate with each other -- connects with the software program.
      • API endpoints = specific digital location where requests for info are sent by one program to retrieve the digital resource that exists there. Endpoints specify where APIs can access resources, help guarantee the proper functioning of the incorporated software.

6 of 27

How do APIs work? (Part 2)

  • There are FOur ways APIS can work (depending on date of creation and reason for creation):
    • SOAP APIS
      • Soap = Simple Object access Protocol
      • Client/Server exchange messages using XML.
        • XML = Extensible Markup Language
      • More popular in the past, less flexible today
    • RPC APis
      • RPC = Remote procedure calls
      • CLient completes function/procedure on server, then server sends output back to client

7 of 27

How do APIs work? (Part 3)

  • Websocket APIs
    • Uses JSON objects to pass data
    • Supports two-way communication between client apps and servers
    • Server can send callback messages to connected clients.
  • REST APIS
    • REST = Representational State Transfer
    • Most popular/flexible API on the web today.
    • Client sends requests to server as data
      • Server uses this client input to start its internal functions and returns this data back to client

8 of 27

Benefits of using REST APis

  • Integration
    • Integrate new apps with existing software systems
    • Increased development speed
      • No functionality written from scratch
    • Leverage existing code
  • Innovation
    • Arrival of new app = changes in entire industries
    • Make changes at api level w/o having to rewrite whole code
  • Expansion
    • Unique opportunity to expand to meet client’s needs on diff. platforms
    • Ex:
      • Maps api allows Map Info integration via websites, Android, ios, etc.
      • Any biz can do similar things by using free/Paid apis
  • Ease of maintenance
    • APi acts as a gateway between two systems
    • Each system = has to make changes internally to prevent impact to API
      • This way, any code changes by one party don’t impact another party.

9 of 27

Intro to the Twitter Bot

10 of 27

What is a twitter bot?

  • In essence, a twitter bot is a type of software bot that controls a twitter account via the TwiTter ApI.

11 of 27

How Twitter bots Work

  • Twitter bots are able to autonomously perform actions such as:
    • tweeting
    • re-tweeting
    • liking
    • following
    • unfollowing
    • direct messaging

12 of 27

Other notes about Twitter APIS

  • versions
    • recently, tw api released apiv2.
      • largest upgrade of api since 2012.
        • new endpoints
        • New and more detailed data objects
        • Advanced metrics
        • etc.
  • Access levels:
    • Essential
    • elevated
    • Academic research
    • Elevated + (Coming soon)
      • Each access level has different rules and limits, depending on the needs of your project.
  • Other offerings
    • Enterprise APIs (Formerly Gnip 2.0)
    • Premium v1.1
    • Standard v1.1
      • These offer scalable access to twitter’s data, incl. better APIS, endpoints, etc.

13 of 27

How To make a twitter bot

  1. Apply for a twitter developer account

(Visit https://developer.twitter.com/)

  1. Create a twitter project and app
  2. Adjust twitter app settings according to your needs
  3. generate your access token and secret access token (API credentials)
    1. Note: save your credentials in a safe place and do not share with anyone!
  4. program your twitter bot
    • Python is simples/most popular choice for this

14 of 27

Benefits of creating a Twitter bot

  • useful
    • Twitter bots can provide useful information or functions to users
  • Automated
    • allows for automation of tasks simply by interacting with the bot on twitter
  • Quick
    • Twitter bots post and respond quickly
  • Entertaining
    • there are Lots of fun and interesting twitter bots to follow and use
  • Good to put on resume
    • Projects like Twitter bots can be added to your resume, github, or linkedin

15 of 27

DOWnsides of Twitter bots

  • SPAM
    • bots can be programmed to spam messages on twitter, creating cluttered feeds
  • SCAM
    • Bots can promote schemes to steal your personal information or carry out other malicious activities
  • False Information
    • Auto-generated messages can potentially lead to the posting and sharing of false information

16 of 27

Examples of Twitter Bots on Twitter - EARTHQUake robot

17 of 27

Examples of Twitter Bots on Twitter - Remind me of this tweet

18 of 27

Examples of Twitter Bots on Twitter - make it a quote

19 of 27

Twitter Bot Demo

20 of 27

Twitter Bot Information:

  • Name of Bot: MLBRANDOMSEASONSIMBOT
  • Twitter Handle: @SeasonRandom
  • Created: NoVember 2022
  • Language: python
  • Reason for Creating the bot:
    • I love Baseball, and I have a keen interest in baseball stats. I was also inspired by the mlb Sh*tpost Bot a ton, as it tweeted random statements with random (Actual) Mlb players in them.

21 of 27

Twitter Bot Code:

  • SIX different Python files:
    • Twitterbotmain (Where the tweet is made)
    • PlayernameNl (Player names from the National league)
    • PLAYernameAl (Player names from the American league)
    • BaseballPositions (All positions on a Baseball diamond)
    • MLBTeams (Every mlb team)
    • Credentials (APi keys)

22 of 27

Twitter Bot Resources

23 of 27

tWITTER bOT/api rESOURCES

  1. wHAT IS AN api? - aws

https://aws.amazon.com/what-is/api/

  1. Twitter Bot Documentation

https://developer.twitter.com/en/docs/twitter-api

  1. Rest api/Creating a twitter bot with python

https://www.crmcrate.com/web-api/what-is-rest-api-create-a-twitter-api-using-python/

  1. Earthquake Robot - Tw

https://twitter.com/earthquakeBot

  1. Remind me of this tweet - Tw

https://twitter.com/RemindMe_OfThis

24 of 27

tWITTER bOT/api rESOURCES (Cont).

  1. Make it a quote - TW

https://twitter.com/MakeItAQuote

  1. MLBRANDOMSEASONSIMBOT - TW

https://twitter.com/SeasonRandom

  1. Create Your Own Twitter Bot in Python 3.10 Tutorial (2022 Edition) - Indently (yt)

https://www.youtube.com/watch?v=2UBcRiddwAo

  1. How To Create A Twitter Bot With Python | Build a Startup #4 - CS dojo (yt)

https://www.youtube.com/watch?v=W0wWwglE1Vc

  1. Stem/Compsci Resources google drive folder

https://drive.google.com/drive/folders/1ZC5Jk1b8GiL0NF298zLMTkaGE1l2f2Xa?usp=sharing

25 of 27

E-Board Elections

26 of 27

27 of 27

Thank you!