twitterapi.users.follower module

user.py: Implementation of Twitter Follower lookup endpoint.

“The follows lookup endpoints enable you to explore and analyze relationships between users, which is sometimes called network analysis. Specifically, there are two REST endpoints that return user objects representing who a specified user is following, or who is following a specified user.” (Source: https://developer.twitter.com/en/docs/twitter-api/users/follows/introduction)

Find the Open API Spec under: https://api.twitter.com/2/openapi.json

Examples

Get followers by id:

import os
os.environ["BEARER_TOKEN"] = "xxxxxxxxxxx"
from sparta.twitterapi.users.follower import get_followers_by_id

async for user in get_followers_by_id('1422600096324231168'):
    print(user.model_dump_json())

Get following by id:

import os
os.environ["BEARER_TOKEN"] = "xxxxxxxxxxx"
from sparta.twitterapi.users.follower import get_following_by_id

async for user in get_following_by_id('1422600096324231168'):
    print(user.model_dump_json())
async sparta.twitterapi.users.follower.get_followers_by_id(id: str, max_resulsts: int = 1000) AsyncGenerator[User, None]

Returns Users who are followers of the specified User ID.

Parameters:
  • id (str) – The ID of the User to lookup.

  • max_resulsts (int, optional) – The maximum number of results. Defaults to 1000.

Raises:
  • Exception – Cannot get the search result due to an http error.

  • Exception – User not found error.

Returns:

AsyncGenerator that yields Twitter User objects.

Return type:

AsyncGenerator[User, None]

Yields:

Iterator[AsyncGenerator[User, None]] – A Twitter User object.

async sparta.twitterapi.users.follower.get_following_by_id(id: str, max_resulsts: int = 1000) AsyncGenerator[User, None]

Returns Users that are being followed by the provided User ID.

Parameters:
  • id (str) – The ID of the User to lookup.

  • max_resulsts (int, optional) – The maximum number of results. Defaults to 1000.

Raises:
  • Exception – Cannot get the search result due to an http error.

  • Exception – User not found error.

Returns:

AsyncGenerator that yields Twitter User objects.

Return type:

AsyncGenerator[User, None]

Yields:

Iterator[AsyncGenerator[User, None]] – A Twitter User object.