• Stars
    star
    372
  • Rank 114,219 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Python API for Botometer by OSoMe

Botometer Python API

A Python API for Botometer by OSoMe. Previously known as botornot-python.

Behind the scenes, this uses the Botometer's HTTP endpoint, available via RapidAPI.

RapidAPI usage/account related questions should be posted on RapidAPI discussion.

[Change Note/Announcement]

May, 2023

Twitter is in the process of suspending free API access for third-party developers. Once the Botometer users lose access to Twitter API V1.1, they can no longer obtain fresh data needed for Botometer Pro API. For the time being, we will keep the Botometer Pro API endpoints alive so that users can analyze data collected before. Users wishing for a refund for the latest billing cycle of the Botometer Pro API can send their requests to RapidAPI ([email protected]) directly.

We are actively working on new Botometer Pro API endpoints compatible with Twitter API V2.0 data. The goal is to allow users who can obtain data from Twitter (through purchase or other approaches) to continue using Botometer API for analysis. Please stay tuned for the updates.

September, 2021

We have a minor update for botometer-python.

Recently Tweepy had a major upgrade (v3.10.0 -> v4.0.0) that is not back compatible. Upgrading your local Tweepy may break botometer-python and throw "No module named 'tweepy.error'" error. To fix it, simply downgrade Tweepy to previous versions such as v3.10.0.

We upgraded botometer-python to v1.6.1 to specify the acceptable versions of Tweepy. There is nothing you need to do if you already have the correct version of Tweepy.

September, 2020

We have a major update for Botometer:

  1. Botometer has been upgraded to V4, and you can use the /4/check_account endpiont to access it.
  2. The response of /4/check_account is reorganized.
  3. A new endpoint for BotometerLite is added. It allows checking accounts in bulk.

You can see the full announcement for details.

Due to the update, please upgrade botometer-python in your local environment to the newest version. You may also need to modify your code to adapt to the new response from the API. For more information, check out the documentation below. If you want to try the new BotometerLite API, checkout the documentation below.

May, 2020

We have made some changes to our API, please read the announcement for details. Due to the API change, the old botometer-python package might stop to work. Please upgrade it in your local environment to the newest version.

Help

You probably want to have a look at Troubleshooting & FAQ in the wiki. Please feel free to suggest and/or contribute improvements to that page.

Prior to Utilizing Botometer

To begin using Botometer, you must follow the steps below before running any code:

  1. Create a free RapidAPI account.
  2. Subscribe to Botometer Pro on RapidApi by selecting a plan.

    There is a completely free version (which does not require any credit card information) for testing purposes.

  3. Create a Twitter application via https://developer.twitter.com/

    Botometer utilizes the access credentials provided by Twitter for the application.

  4. Ensure Botometer Pro's dependencies are already installed.

    See the Dependencies section for details.

Note: These steps are necessary to access credentials and download other packages which are needed for Botometer to work properly. Please see RapidAPI and Twitter Access Details below for more details on this topic.

Quickstart

From your command shell, run

pip install botometer

Botometer-V4

To access the Botometer-V4 API, enter something like this in a Python shell or script:

import botometer

rapidapi_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
twitter_app_auth = {
    'consumer_key': 'xxxxxxxx',
    'consumer_secret': 'xxxxxxxxxx',
    'access_token': 'xxxxxxxxx',
    'access_token_secret': 'xxxxxxxxxxx',
  }
bom = botometer.Botometer(wait_on_ratelimit=True,
                          rapidapi_key=rapidapi_key,
                          **twitter_app_auth)

# Check a single account by screen name
result = bom.check_account('@clayadavis')

# Check a single account by id
result = bom.check_account(1548959833)

# Check a sequence of accounts
accounts = ['@clayadavis', '@onurvarol', '@jabawack']
for screen_name, result in bom.check_accounts_in(accounts):
    # Do stuff with `screen_name` and `result`

Result:

{
    "cap": {
        "english": 0.8018818614025648,
        "universal": 0.5557322218336633
    },
    "display_scores": {
        "english": {
            "astroturf": 0.0,
            "fake_follower": 4.1,
            "financial": 1.5,
            "other": 4.7,
            "overall": 4.7,
            "self_declared": 3.2,
            "spammer": 2.8
        },
        "universal": {
            "astroturf": 0.3,
            "fake_follower": 3.2,
            "financial": 1.6,
            "other": 3.8,
            "overall": 3.8,
            "self_declared": 3.7,
            "spammer": 2.3
        }
    },
    "raw_scores": {
        "english": {
            "astroturf": 0.0,
            "fake_follower": 0.81,
            "financial": 0.3,
            "other": 0.94,
            "overall": 0.94,
            "self_declared": 0.63,
            "spammer": 0.57
        },
        "universal": {
            "astroturf": 0.06,
            "fake_follower": 0.64,
            "financial": 0.3133333333333333,
            "other": 0.76,
            "overall": 0.76,
            "self_declared": 0.74,
            "spammer": 0.47
        }
    },
    "user": {
        "majority_lang": "en",
        "user_data": {
            "id_str": "11330",
            "screen_name": "test_screen_name"
        }
    }
}

Meanings of the elements in the response:

  • user: Twitter user object (from the user) plus the language inferred from majority of tweets
  • raw scores: bot score in the [0,1] range, both using English (all features) and Universal (language-independent) features; in each case we have the overall score and the sub-scores for each bot class (see below for subclass names and definitions)
  • display scores: same as raw scores, but in the [0,5] range
  • cap: conditional probability that accounts with a score equal to or greater than this are automated; based on inferred language

Meanings of the bot type scores:

  • fake_follower: bots purchased to increase follower counts
  • self_declared: bots from botwiki.org
  • astroturf: manually labeled political bots and accounts involved in follow trains that systematically delete content
  • spammer: accounts labeled as spambots from several datasets
  • financial
: bots that post using cashtags
  • other: miscellaneous other bots obtained from manual annotation, user feedback, etc.

For more information on the response object, consult the API Overview on RapidAPI.

BotometerLite

In September, 2020, the BotometerLite endpoint was added. It leverages a lightweighted model and allows detecting likely bots in bulk. Before accessing it, please make sure you have subscribed to the ULTRA plan on RapidAPI.

Unlike Botometer-V4, BotometerLite just needs the user profile information and the timestamp of when the information was collected to perform bot detection. There are two modes for BotometerLite: non-Twitter mode and Twitter mode.

If you have already collected at least one tweet for each account you want to check, you can use the non-Twitter mode. In this mode, you only need a RapidAPI key.

import botometer

rapidapi_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
blt = botometer.BotometerLite(rapidapi_key=rapidapi_key)

# Prepare a list of tweets from the users that you want to perform bot detection on.
# The list should contain no more than 100 tweets.
tweet_list = [tweet1, tweet2, ...] 

blt_scores = blt.check_accounts_from_tweets(tweet_list)

Result:

[
    {"botscore": 0.65, "tweet_id": "1234",  "user_id": 1111},
    {"botscore": 0.29, "tweet_id": "12345", "user_id": 2222}
]

Note that the tweet_id is also included in case multiple tweets from the same user are passed to the API.

If you only have a set of user_ids or screen_names, you will have to use the Twitter mode. In addition to the RapidAPI key, this mode also requires a valid Twitter APP key. The package would first query the Twitter user lookup API to fetch the user profiles, then pass the data to the Botometer Pro API for the bot scores.

import botometer

rapidapi_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
twitter_app_auth = {
    'consumer_key': 'xxxxxxxx',
    'consumer_secret': 'xxxxxxxxxx',
    'access_token': 'xxxxxxxxx',
    'access_token_secret': 'xxxxxxxxxxx',
  }
  
blt_twitter = botometer.BotometerLite(rapidapi_key=rapidapi_key, **twitter_app_auth)

# Prepare a list of screen_names you want to check.
# The list should contain no more than 100 screen_names; please remove the @
screen_name_list = ['yang3kc', 'onurvarol', 'clayadavis']
blt_scores = blt_twitter.check_accounts_from_screen_names(screen_name_list)

# Prepare a list of user_ids you want to check.
# The list should contain no more than 100 user_ids.
user_id_list = [1133069780917850112, 77436536, 1548959833]
blt_scores = blt_twitter.check_accounts_from_user_ids(user_id_list)

Result:

[
    {"botscore": 0.17, "tweet_id": null, "user_id": 1133069780917850112},
    {"botscore": 0.2,  "tweet_id": null, "user_id": 77436536},
    {"botscore": 0.16, "tweet_id": null, "user_id": 1548959833}
]

The tweet_id is set to null in this mode.

Note that in the non-Twitter mode, the returned scores reflect the status of the accounts when the tweets were collected. In the Twitter mode, on the other hand, the scores reflect the status of the accounts when you run the code, just like the Botometer-V4 endpoint.

Install instructions

This package is on PyPI so you can install it with pip:

$ pip install botometer

Dependencies

Python dependencies

Both of these dependencies are available via pip, so you can install both at once with

pip install requests tweepy

RapidAPI and Twitter Access Details

RapidAPI key

Our API is served via RapidAPI. You must sign up for a free account in order to obtain a RapidAPI secret key. The easiest way to get your secret key is to visit our API endpoint page and look in the endpoint's header parametsrs for the "X-RapidAPI-Key" as shown below:

Screenshot of RapidAPI header parameters

Twitter app

In order to access Twitter's API, one needs to have/create a Twitter app. Once you've created an app, the authentication info can be found in the "Keys and Access Tokens" tab of the app's properties: Screenshot of app "Keys and Access Tokens"

Authentication

By default, Botometer uses user authentication when interacting with Twitter's API as it is the least restrictive and the ratelimit matches with Botometer's Pro plan: 180 requests per 15-minute window. One can instead use Twitter's application authentication in order to take advantage of the higher ratelimit that matches our Ultra plan: 450 requests per 15-minute window. Do note the differences between user and app-only authentication found under the header "Twitter API Authentication Model" in Twitter's docs on authentication.

To use app-only auth, just omit the access_token and access_token_secret in the Botometer constructor.

import botometer

rapidapi_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # now it's called rapidapi key
twitter_app_auth = {
    'consumer_key': 'xxxxxxxx',
    'consumer_secret': 'xxxxxxxxxx'
    }
bom = botometer.Botometer(wait_on_ratelimit=True,
                          rapidapi_key=rapidapi_key,
                          **twitter_app_auth)

References

  • Botometer v4: Mohsen Sayyadiharikandeh, Onur Varol, Kai-Cheng Yang, Alessandro Flammini, Filippo Menczer. "Detection of Novel Social Bots by Ensembles of Specialized Classifiers." DOI, ArXiv

  • BotometerLite: Yang, K.; Varol, O.; Hui, P.; and Menczer, F. "Scalable and Generalizable Social Bot Detection through Data Selection." AAAI (2020). DOI, ArXiv

  • Botometer v3: Yang, Kai‐Cheng, Onur Varol, Clayton A. Davis, Emilio Ferrara, Alessandro Flammini, and Filippo Menczer. "Arming the public with artificial intelligence to counter social bots." Human Behavior and Emerging Technologies 1, no. 1 (2019): 48-61. DOI, ArXiv

  • Botometer v2: Varol, Onur, Emilio Ferrara, Clayton A. Davis, Filippo Menczer, and Alessandro Flammini. "Online Human-Bot Interactions: Detection, Estimation, and Characterization." ICWSM (2017). AAAI, ArXiv

  • Botometer v1 aka BotOrNot: Davis, C. A., Varol, O., Ferrara, E., Flammini, A., & Menczer, F. (2016, April). "BotOrNot: A system to evaluate social bots". In Proceedings of the 25th International Conference Companion on World Wide Web (pp. 273-274). International World Wide Web Conferences Steering Committee. DOI, ArXiv

  • Varol O., Davis C., Menczer, F., Flammini, A. "Feature Engineering for Social Bot Detection", Feature Engineering for Machine Learning and Data Analytics Google Books

  • Ferrara, Emilio, Onur Varol, Clayton Davis, Filippo Menczer, and Alessandro Flammini. "The rise of social bots." Communications of the ACM 59, no. 7 (2016): 96-104. DOI, ArXiv

More Repositories

1

hoaxy-backend

Backend component for Hoaxy, a tool to visualize the spread of claims and fact checking
Python
138
star
2

hoaxy-frontend

Frontend component for Hoaxy, a tool to visualize the spread of claims and fact checking
JavaScript
72
star
3

BotSlayer-CE

BotSlayer Community Edition
Vue
35
star
4

DrifterBot

Source code and data for paper "Neutral Bots Probe Political Bias on Social Media" by Chen et al.
Jupyter Notebook
31
star
5

osometweet

OSoMe Twitter tools. Including a package like tweepy but for the v2 Twitter api.
Python
30
star
6

klatsch

a framework and language for exploring and analyzing feeds of social media data.
Java
23
star
7

HoaxyBots

Code and instructions to reproduce the results in the paper 'The spread of low-credibility content by social bots' by Shao et al.
Jupyter Notebook
20
star
8

coordination-detection

Python library to detect coordinated campaigns on social media
Python
18
star
9

CoVaxxy

Global collection of English Twitter posts about COVID-19 vaccines
16
star
10

MEIU22

A collection of cross-platform social media posts about the 2022 U.S. midterm elections
Python
13
star
11

AIBot_fox8

This repo contains the code and information for the paper "Anatomy of an AI-powered malicious social botnet"
Python
13
star
12

ChatGPT_domain_rating

Code and data for paper "Large language models can rate news outlet credibility"
Python
12
star
13

osome-mashups

OSoMe API mashups
Jupyter Notebook
11
star
14

Botometer101

This repository contains the code for the paper "Botometer 101: Social bot practicum for computational social scientists."
Jupyter Notebook
10
star
15

IC2S2_OSoMe_tutorial_2024

OSoMe tutorial at IC2S2 2024
Jupyter Notebook
5
star
16

AI_fact_checking

We conduct a preregistered experiment to investigate whether fact checks provided by a large language model can serve as an effective misinformation intervention.
HTML
5
star
17

fake_gan_accounts

Characteristics and prevalence of fake social media profiles with AI-generated faces
Python
5
star
18

SimSoM

A minimal model of information-sharing on a social media platform.
Jupyter Notebook
4
star
19

BEV

Bot Electioneering Volume
3
star
20

misinfo-partisanship-hksmisinforeview-2021

Code for replicating "Right and left, partisanship predicts vulnerability to misinformation" by Dimitar Nikolov, Alessandro Flammini and Filippo Menczer
Jupyter Notebook
3
star
21

CoVaxxy-Misinfo

Reproducibility code for "Online misinformation is linked to early COVID-19 vaccination hesitancy and refusal"
Python
3
star
22

Rematch-RARE

Rematch: Robust and Efficient Matching of Local Knowledge Graphs for Improved Structural and Semantic Similarity
Python
2
star
23

llm_domain_rating

Code and data for paper "Accuracy and Political Bias of News Source Credibility Ratings by Large Language Models"
Python
1
star
24

low-cred-superspreaders

Develop and test a simple metric (FIB index) for predicting superspreaders of misinformation on social media.
Jupyter Notebook
1
star