Skip to main content

Twitter Accounts Activity API Client Library for Python

Project description

Twitivity

PyPI - Python Version PyPI - License

Twitter Accounts Activity API Client Library for Python

  • :key: Performs CRC validation
  • :memo: Registers webhooks
  • :sound: Subscribes to current user's context
  • :headphones: Gets activities of the user in real time.

Usage

Refer to Twitter's getting started guide on how to create an application. Then set up dev environment label for the application.

Credentials

App :arrow_right: Details :arrow_right: Keys and Tokens

Add the credentials to the environment variables.

~$ export consumer_key=API_KEY
~$ export consumer_secret=API_SECRET_KEY
~$ export access_token=ACCESS_TOKEN
~$ export access_token_secret=ACCESS_TOKEN_SECRET
~$ export env_name=APP_ENV_NAME

Install & run ngrok.

~$ ./ngrok http 5000 

Stream events in real time.

# stream_events.py

>>> from twitivity import Event
>>> import json

>>> class StreamEvent(Event):
     CALLBACK_URL: str = "https://yourdomain.com/listener"
    
     def on_data(self, data: json) -> None:
         # process data

>>> stream_events = StreamEvent()
>>> stream_events.listen()

Setup

To register the callback URL run the program above alongside the one below. This will register your webhook URL and subscribe to activities. This only has to be setup once.

# configure.py

from twitivity import Activity

>>> account_activity = Activity()
>>> account_activity.register_webhook("https://youdomain.com/listener")
>>> account_activity.subscribe()

The registration will return json response

{
    'id': '1198870971131686912', # webhook id
    'url': 'https://1f4396a1.ngrok.io/twitter/callback', 
    'valid': True, 
    'created_timestamp': '2019-11-25 07:48:08 +0000'
}

Installation

~$ pip install twitivity

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twitivity-0.1.2.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file twitivity-0.1.2.tar.gz.

File metadata

  • Download URL: twitivity-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5rc1

File hashes

Hashes for twitivity-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0cb29664986b207c069be8b17a22c8147c5ee990cff37a0d9c2d1703ee66fc4e
MD5 f248f1c1e404d78df180b76d1b590723
BLAKE2b-256 9aa5a4129c0df3a0a0a78fcd9fabfadc5ef7286ad9a25ff91b4a1746f0d9205b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page