Skip to content

4. API Reference

Dev Jones edited this page Mar 25, 2024 · 13 revisions

This section of the documentation serves as a comprehensive guide to the classes, methods, and models available in PyTweetToolkit. Here, you can find detailed information on how to use the toolkit to interact with Twitter.

Overview

  • Brief description of the API
  • Authentication requirements
  • Rate limiting and best practices

Classes

Bookmark Actions

The BookmarkActions class in PyTweetToolkit is dedicated to managing Twitter bookmarks. This class allows users to bookmark tweets, remove bookmarks, and retrieve a list of bookmarked tweets using Twitter's GraphQL API. It inherits from an authentication base class for necessary credentials handling.

Rate Limits:

  • bookmark_tweet: 500 actions per 15-minute window
  • unbookmark_tweet: 500 actions per 15-minute window
  • get_bookmarks: 500 actions per 15-minute window

Methods:

Bookmark Tweet

  • bookmark_tweet(self, tweet_id: str) -> tweet_model.Tweet

    Bookmarks a specified tweet.

    • Parameters: tweet_id (str) - The ID of the tweet to bookmark.
    • Returns: tweet_model.Tweet - An instance representing the bookmarked tweet.
    • Raises: HTTP errors or specific exceptions based on API response.
    • Rate Limit: 500 actions per 15 minutes.

Unbookmark Tweet

  • unbookmark_tweet(self, tweet_id: str) -> tweet_model.Tweet

    Removes a bookmark from a specified tweet.

    • Parameters: tweet_id (str) - The ID of the tweet to unbookmark.
    • Returns: tweet_model.Tweet - An instance representing the tweet post-unbookmark.
    • Raises: HTTP errors or specific exceptions based on API response.
    • Rate Limit: 500 actions per 15 minutes.

Get bookmarks

  • get_bookmarks(self, cursor: str = "") -> tuple[list[tweet_model.Tweet], str, str]

    Fetches a list of bookmarked tweets, with pagination support.

    • Parameters: cursor (str, optional) - Pagination cursor for bookmark retrieval.
    • Returns: tuple[list[tweet_model.Tweet], str, str] - A tuple containing a list of bookmarked tweets, the next cursor, and the previous cursor.
    • Raises: HTTP errors or specific exceptions based on API response.
    • Rate Limit: 500 actions per 15 minutes.

Friendship Actions

The FriendshipActions class in PyTweetToolkit handles various actions related to Twitter friendships. This includes following and unfollowing users, as well as managing follow requests, all through Twitter's API. It uses authentication from the base class for API requests.

Rate Limits: These actions adhere to Twitter's standard API rate limits, which users should consult in Twitter's API documentation for the most up-to-date information.

Methods:

Follow User

  • follow_user(self, user_id: str) -> user_model.User

    Initiates following a user by their ID and returns details about the followed user.

    • Parameters: user_id (str) - The ID of the user to follow.
    • Returns: user_model.User - Details of the followed user.
    • Rate Limit: Subject to Twitter's standard API rate limits.

Unfollow User

  • unfollow_user(self, user_id: str) -> user_model.User

    Stops following a user by their ID and returns details about the unfollowed user.

    • Parameters: user_id (str) - The ID of the user to unfollow.
    • Returns: user_model.User - Details of the unfollowed user.
    • Rate Limit: Subject to Twitter's standard API rate limits.

Follow Requests

  • follow_requests(self, user_id: str) -> list[user_model.User]

    Retrieves a list of users who have requested to follow the authenticated user.

    • Parameters: user_id (str) - The user ID of the authenticated user.
    • Returns: list[user_model.User] - A list of users who have requested to follow.
    • Rate Limit: Subject to Twitter's standard API rate limits.

Accept Follow Request

  • accept_follow_request(self, user_id: str) -> user_model.User

    Accepts a follow request from a specific user by their ID, returning the user's details post-acceptance.

    • Parameters: user_id (str) - The ID of the user whose follow request is accepted.
    • Returns: user_model.User - The user's details after accepting the follow request.
    • Rate Limit: Subject to Twitter's standard API rate limits.

Reject Follow Request

  • reject_follow_request(self, user_id: str) -> user_model.User

    Rejects a follow request from a specific user by their ID, returning the user's details post-rejection.

    • Parameters: user_id (str) - The ID of the user whose follow request is rejected.
    • Returns: user_model.User - The user's details after rejecting the follow request.
    • Rate Limit: Subject to Twitter's standard API rate limits.

Clone this wiki locally