|
1 | 1 | # Twitter Plugin for GAME SDK |
2 | 2 |
|
3 | | -The Twitter plugin is a lightweight wrapper over commonly-used twitter API calls. It can be used as a executable on its own or by combining multiple of these into an executable. |
| 3 | +The **Twitter Plugin** provides a lightweight interface for integrating Twitter (X) functionality into your GAME SDK agents. Built on top of [`virtuals_tweepy`](https://pypi.org/project/virtuals-tweepy/) by the Virtuals team — a maintained fork of [`Tweepy`](https://pypi.org/project/tweepy/)) — this plugin lets you easily post tweets, fetch data, and execute workflows through agent logic. |
| 4 | + |
| 5 | +## 📜 GAME X API Usage Terms & Rules |
| 6 | +By using our GAME API, you agree to the [Terms of Use](https://virtualsprotocol.notion.site/Terms-of-Use-2152d2a429e980f09a74c85c0a5974c4?source=copy_link) and [GAME X API Terms](https://virtualsprotocol.notion.site/Agents-on-X-Rulebook-1972d2a429e980ddaa85da3c903afade?pvs=74). |
| 7 | + |
| 8 | +## 🚀 API Access Tiers |
| 9 | +Virtuals sponsors the community with a **Twitter Enterprise API access plan**, using OAuth 2.0 with PKCE. This provides: |
| 10 | + |
| 11 | +## 🚀 API Access Tiers |
| 12 | +### Tier 1 — Default |
| 13 | +- Higher rate limits: **50 calls / 5 minutes** |
| 14 | +- Smoother onboarding |
| 15 | +- Free usage via your `GAME_API_KEY` |
| 16 | + |
| 17 | +### Tier 2 — Elevated |
| 18 | +- Even higher rate limits |
| 19 | +- Requires approval from the Virtuals team. Request access via Discord → @virtualsio |
| 20 | + |
| 21 | +--- |
| 22 | +Use it standalone or compose multiple Twitter actions as part of a larger agent job. |
4 | 23 |
|
5 | 24 | ## Installation |
6 | 25 |
|
7 | | -From this directory (`twitter`), run the installation: |
| 26 | +You can install the plugin using either `poetry` or `pip`: |
8 | 27 |
|
9 | 28 | ```bash |
| 29 | +# Using Poetry (from the plugin directory) |
10 | 30 | poetry install |
11 | 31 | ``` |
| 32 | +or |
| 33 | +```bash |
| 34 | +# Using pip (recommended for integration projects) |
| 35 | +pip install twitter_plugin_gamesdk |
| 36 | +``` |
12 | 37 |
|
13 | | -## Usage |
| 38 | +--- |
14 | 39 |
|
15 | | -The Twitter plugin can be initialized in one of two ways: |
| 40 | +## Authentication Methods |
| 41 | +Virtuals sponsors the community with a **Twitter Enterprise API access plan**, using OAuth 2.0 with PKCE. This provides: |
16 | 42 |
|
17 | | -1. Using GAME's X enterprise API credentials (higher rate limits) |
| 43 | +- Higher rate limits: **35 calls / 5 minutes** |
| 44 | +- Smoother onboarding |
| 45 | +- Free usage via your `GAME_API_KEY` |
18 | 46 |
|
19 | | - - To get the access token for this option, run the following command: |
| 47 | +#### 1. Get Your Access Token |
20 | 48 |
|
21 | | - ```bash |
22 | | - poetry run twitter-plugin-gamesdk auth -k <GAME_API_KEY> |
23 | | - ``` |
| 49 | +Run the following command to authenticate using your `GAME_API_KEY`: |
24 | 50 |
|
25 | | - You will see the following output: |
| 51 | +```bash |
| 52 | +poetry run twitter-plugin-gamesdk auth -k <GAME_API_KEY> |
| 53 | +``` |
26 | 54 |
|
27 | | - ```bash |
28 | | - Waiting for authentication... |
| 55 | +This will prompt: |
29 | 56 |
|
30 | | - Visit the following URL to authenticate: |
31 | | - https://x.com/i/oauth2/authorize?response_type=code&client_id=VVdyZ0t4WFFRMjBlMzVaczZyMzU6MTpjaQ&redirect_uri=http%3A%2F%2Flocalhost%3A8714%2Fcallback&state=866c82c0-e3f6-444e-a2de-e58bcc95f08b&code_challenge=K47t-0Mcl8B99ufyqmwJYZFB56fiXiZf7f3euQ4H2_0&code_challenge_method=s256&scope=tweet.read%20tweet.write%20users.read%20offline.access |
32 | | - ``` |
| 57 | +```bash |
| 58 | +Waiting for authentication... |
33 | 59 |
|
34 | | - After authenticating, you will receive the following message: |
| 60 | +Visit the following URL to authenticate: |
| 61 | +https://x.com/i/oauth2/authorize?... |
35 | 62 |
|
36 | | - ```bash |
37 | | - Authenticated! Here's your access token: |
38 | | - apx-<xxx> |
39 | | - ``` |
| 63 | +Authenticated! Here's your access token: |
| 64 | +apx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 65 | +``` |
| 66 | +
|
| 67 | +#### 2. Store Your Access Token |
40 | 68 |
|
41 | | - - Set the access token as an environment variable called `GAME_TWITTER_ACCESS_TOKEN` (e.g. using a `.bashrc` or a `.zshrc` file). |
42 | | - - Import and initialize the plugin to use in your worker: |
| 69 | +We recommend storing environment variables in a `.env` file: |
43 | 70 |
|
44 | | - ```python |
45 | | - import os |
46 | | - from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin |
| 71 | +``` |
| 72 | +# .env |
| 73 | +
|
| 74 | +GAME_TWITTER_ACCESS_TOKEN=apx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 75 | +``` |
47 | 76 |
|
48 | | - # Define your options with the necessary credentials |
49 | | - options = { |
50 | | - "credentials": { |
51 | | - "gameTwitterAccessToken": os.environ.get("GAME_TWITTER_ACCESS_TOKEN") |
52 | | - }, |
53 | | - } |
54 | | - # Initialize the TwitterPlugin with your options |
55 | | - twitter_plugin = TwitterPlugin(options) |
| 77 | +Then, use `load_dotenv()` to load them: |
56 | 78 |
|
57 | | - # Post a tweet |
58 | | - post_tweet_fn = twitter_plugin.get_function('post_tweet') |
59 | | - post_tweet_fn("Hello world!") |
60 | | - ``` |
| 79 | +```python |
| 80 | +import os |
| 81 | +from dotenv import load_dotenv |
| 82 | +from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin |
61 | 83 |
|
62 | | -2. Using your own X API credentials |
| 84 | +load_dotenv() |
| 85 | +
|
| 86 | +options = { |
| 87 | + "credentials": { |
| 88 | + "game_twitter_access_token": os.environ.get("GAME_TWITTER_ACCESS_TOKEN") |
| 89 | + } |
| 90 | +} |
| 91 | +
|
| 92 | +twitter_plugin = TwitterPlugin(options) |
| 93 | +client = twitter_plugin.twitter_client |
| 94 | +
|
| 95 | +client.create_tweet(text="Tweeting with GAME Access Token!") |
| 96 | +``` |
| 97 | +--- |
63 | 98 |
|
64 | | - - If you don't already have one, create a X (twitter) account and navigate to the [developer portal](https://developer.x.com/en/portal/dashboard). |
65 | | - - Create a project app, generate the following credentials and set them as environment variables (e.g. using a `.bashrc` or a `.zshrc` file): |
66 | | - - `TWITTER_BEARER_TOKEN` |
67 | | - - `TWITTER_API_KEY` |
68 | | - - `TWITTER_API_SECRET_KEY` |
69 | | - - `TWITTER_ACCESS_TOKEN` |
70 | | - - `TWITTER_ACCESS_TOKEN_SECRET` |
71 | | - - Import and initialize the plugin to use in your worker: |
| 99 | +## Examples |
72 | 100 |
|
73 | | - ```python |
74 | | - import os |
75 | | - from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin |
| 101 | +Explore the [`examples/`](./examples) directory for sample scripts demonstrating how to: |
76 | 102 |
|
77 | | - # Define your options with the necessary credentials |
78 | | - options = { |
79 | | - "credentials": { |
80 | | - "bearerToken": os.environ.get("TWITTER_BEARER_TOKEN"), |
81 | | - "apiKey": os.environ.get("TWITTER_API_KEY"), |
82 | | - "apiSecretKey": os.environ.get("TWITTER_API_SECRET_KEY"), |
83 | | - "accessToken": os.environ.get("TWITTER_ACCESS_TOKEN"), |
84 | | - "accessTokenSecret": os.environ.get("TWITTER_ACCESS_TOKEN_SECRET"), |
85 | | - }, |
86 | | - } |
87 | | - # Initialize the TwitterPlugin with your options |
88 | | - twitter_plugin = TwitterPlugin(options) |
| 103 | +- Post tweets |
| 104 | +- Reply to mentions |
| 105 | +- Quote tweets |
| 106 | +- Fetch user timelines |
| 107 | +- And more! |
89 | 108 |
|
90 | | - # Post a tweet |
91 | | - post_tweet_fn = twitter_plugin.twitter_client.create_tweet |
92 | | - post_tweet_fn(text="Hello world! This is a test tweet from the Twitter Plugin!") |
93 | | - ``` |
| 109 | +--- |
94 | 110 |
|
95 | | -For detailed documentation on each function's parameters and usage, please refer to the [Tweepy Client Documentation](https://docs.tweepy.org/en/stable/client.html). |
| 111 | +## API Reference |
96 | 112 |
|
97 | | -Example usage: |
| 113 | +This plugin wraps [`virtuals_tweepy`](https://pypi.org/project/virtuals-tweepy/), which is API-compatible with [Tweepy’s client interface](https://docs.tweepy.org/en/stable/client.html). Refer to their docs for supported methods and parameters. |
98 | 114 |
|
99 | | -You can refer to the example files in the `examples` directory for more examples on how to call the twitter functions. |
| 115 | +--- |
0 commit comments