Skip to main content

PyPI - Version GitHub License

django-twitter-auth-manager

Manage Twitter OAuth 2.0 Authorization Code Flow with PKCE (User Context) authentication by an Django app and store necessary token and refresh token for future uses.

Dependencies

This package depends on the Tweepy library, and Django framework as well as the Django's cache application.

Limitations

The auth manage system is designed to use Twitters Free API plan. That's why uses OAuth 2.0 Authorization Code Flow with PKCE (User Context), for write procedures. So the limitation are set by Twitters Free plan:

  • access token is valid only for 2 hours
  • 1 environment
  • up to 1500 posts per month
  • 50 requests / 24 hours PER APP for tweets
  • 25 requests / 24 hoursPER USER info

More details in: https://developer.twitter.com/en/portal/products/free

Installation

To install django-twitter-auth-manager simply run:

   pip install django-twitter-auth-manager

Configuration

We need to hook django-twitter-auth-manager into our project.

  1. Put django_uptime into your INSTALLED_APPS at settings module:
   INSTALLED_APPS = (
       # other apps
       "django_twitter_auth_manager",
   )
  1. Include the desired url path into your projects main urls.py file:
   from django.urls import include, path

   urlpatterns = [
      ...
      path('twitter/', include('django_twitter_auth_manager.urls')),
      ...
   ]

Usage

  1. Execute the "Authenticate your app" Django admin action from Access Token list panel
  2. Follow the Oauth2 flow procedure
  3. Once the first access token is saved, we can now use the Tweepy client:
   from django_twitter_auth_manager.models import Access_token

   access_token = Access_token.objects.last()
   client = tweepy.Client(access_token.access_token)
   client.create_tweet(text="Hello World!", user_auth=False)

Refresh token

In order to refresh the access token, you can do manually by triggering admin's "Refresh token" action or checking the validity an triggering automatically:

   from django_twitter_auth_manager.models import Access_token
   from django_twitter_auth_manager.views import refresh_token

   access_token = Access_token.objects.last()

   if not access_token.is_valid():
      access_token = refresh_token()

   # Further actions

1.0 (2024-04-25)

Metadata

Release files for django-twitter-auth-manager 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-twitter-auth-manager 1.0
File Size Uploaded
django_twitter_auth_manager-1.0.tar.gz 6.2 kB Details

Release files / django_twitter_auth_manager-1.0.tar.gz

Download URL django_twitter_auth_manager-1.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7c263d40890888b1172302e86cae076a6a0c15efc85021dbf20115076d0542f7
BLAKE2b-256 checksum
How to use checksums
298f2b258315bc408783f6161719bc45234eb63494d227e6f104c02659c37aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page