Skip to content

3. Getting Started

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

This page will guide you through the initial steps needed to start using PyTweetToolkit, from obtaining authentication cookies to performing basic Twitter operations like posting a tweet and following a user.

Obtaining Authentication Cookies

To interact with Twitter through PyTweetToolkit, you need to provide authentication cookies. Here's how to retrieve them:

Step 1: Log in to Twitter

  • Log in to your Twitter account in a web browser.

Step 2: Open Developer Tools

  • Access the developer tools by right-clicking on the page and selecting "Inspect", or use the shortcut Ctrl+Shift+I (or Cmd+Option+I on Mac).

Step 3: Navigate to the Application or Storage Tab

  • Within the developer tools, locate the "Application" or "Storage" tab where cookie information is stored.

Step 4: Find Twitter Cookies

  • Look for the cookies related to the Twitter website, specifically auth_token and ct0.

Step 5: Extract Cookie Values

  • Double-click on the auth_token and ct0 cookies to copy their values.

Step 6: Use Cookie Values as Tokens

  • In your script, use the copied values to replace YOUR_AUTH_TOKEN and YOUR_CSRF_TOKEN.
# Replace YOUR_AUTH_TOKEN and YOUR_CSRF_TOKEN with the actual values.
auth_token = "YOUR_AUTH_TOKEN"
csrf_token = "YOUR_CSRF_TOKEN"

Ensure that you keep these tokens secure and do not share them, as they grant access to your Twitter account.

Quick Start

Below is a simple example to demonstrate how you can use PyTweetToolkit to post a tweet and follow a user.

Posting a Tweet

from PyTweetToolkit import PyTweetClient

# Initialize the client with your authentication tokens
client = PyTweetClient(auth_token=auth_token, csrf_token=csrf_token)

# Post a tweet
client.post_tweet("Hello, world! #MyFirstTweet")

Following a User

# Follow a user by their username
client.follow("python_community")

This example assumes you have set your auth_token and csrf_token with the appropriate values obtained as per the instructions above.

Further Examples

For more examples and detailed usage patterns, refer to the Examples page.