Skip to content

Commit 15a007a

Browse files
committed
GAME twitter readme instructions
1 parent 16f6ca2 commit 15a007a

File tree

1 file changed

+80
-33
lines changed

1 file changed

+80
-33
lines changed

plugins/twitter/README.md

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,86 @@ The Twitter plugin is a lightweight wrapper over commonly-used twitter API calls
55
## Installation
66
From this directory (`twitter`), run the installation:
77
```bash
8-
pip install -e .
8+
poetry install
99
```
1010

1111
## Usage
12-
1. 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).
13-
2. Create a project app, generate the following credentials and set the following environment variables (e.g. using a `.bashrc` or a `.zshrc` file):
14-
- `TWITTER_API_KEY`
15-
- `TWITTER_API_SECRET_KEY`
16-
- `TWITTER_ACCESS_TOKEN`
17-
- `TWITTER_ACCESS_TOKEN_SECRET`
18-
19-
3. Import and initialize the plugin to use in your worker:
20-
```python
21-
import os
22-
from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin
23-
24-
# Define your options with the necessary credentials
25-
options = {
26-
"id": "test_twitter_worker",
27-
"name": "Test Twitter Worker",
28-
"description": "An example Twitter Plugin for testing.",
29-
"credentials": {
30-
"apiKey": os.environ.get("TWITTER_API_KEY"),
31-
"apiSecretKey": os.environ.get("TWITTER_API_SECRET_KEY"),
32-
"accessToken": os.environ.get("TWITTER_ACCESS_TOKEN"),
33-
"accessTokenSecret": os.environ.get("TWITTER_ACCESS_TOKEN_SECRET"),
34-
},
35-
}
36-
# Initialize the TwitterPlugin with your options
37-
twitter_plugin = TwitterPlugin(options)
38-
39-
# Post a tweet
40-
post_tweet_fn = twitter_plugin.get_function('post_tweet')
41-
post_tweet_fn("Hello world!")
42-
```
43-
You can refer to `test_twitter.py` for more examples on how to call the twitter functions.
12+
1. Choose one of the 2 options to initialise the Twitter plugin
13+
- `GameTwitterPlugin`
14+
- This allows one to leverage GAME's X enterprise API credentials (i.e. higher rate limits)
15+
- `TwitterPlugin`
16+
- This allows one to use their own X API credentials
17+
2. Initialise plugin objects, run set-up scripts and use plugin functions
18+
- `GameTwitterPlugin`
19+
- To get the access token to us this plugin, run the following command
20+
```bash
21+
poetry run twitter-plugin-gamesdk auth -k <GAME_API_KEY>
22+
```
23+
You will see the following output:
24+
```bash
25+
Waiting for authentication...
26+
27+
Visit the following URL to authenticate:
28+
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
29+
```
30+
After authenticating, you will receive the following message:
31+
```bash
32+
Authenticated! Here's your access token:
33+
apx-<xxx>
34+
```
35+
- Set the access token as an environment variable called `GAME_TWITTER_ACCESS_TOKEN` (e.g. using a `.bashrc` or a `.zshrc` file):
36+
- Import and initialize the plugin to use in your worker:
37+
```python
38+
import os
39+
from twitter_plugin_gamesdk.game_twitter_plugin import GameTwitterPlugin
40+
41+
# Define your options with the necessary credentials
42+
options = {
43+
"id": "test_game_twitter_plugin",
44+
"name": "Test GAME Twitter Plugin",
45+
"description": "An example GAME Twitter Plugin for testing.",
46+
"credentials": {
47+
"gameTwitterAccessToken": os.environ.get("GAME_TWITTER_ACCESS_TOKEN")
48+
},
49+
}
50+
# Initialize the TwitterPlugin with your options
51+
game_twitter_plugin = GameTwitterPlugin(options)
52+
53+
# Post a tweet
54+
post_tweet_fn = game_twitter_plugin.get_function('post_tweet')
55+
post_tweet_fn("Hello world!")
56+
```
57+
You can refer to `test_game_twitter.py` for more examples on how to call the twitter functions. Note that there is a limited number of functions available. If you require more, please submit a feature requests via Github Issues.
58+
59+
- `TwitterPlugin`
60+
- 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).
61+
- Create a project app, generate the following credentials and set the following environment variables (e.g. using a `.bashrc` or a `.zshrc` file):
62+
- `TWITTER_API_KEY`
63+
- `TWITTER_API_SECRET_KEY`
64+
- `TWITTER_ACCESS_TOKEN`
65+
- `TWITTER_ACCESS_TOKEN_SECRET`
66+
- Import and initialize the plugin to use in your worker:
67+
```python
68+
import os
69+
from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin
70+
71+
# Define your options with the necessary credentials
72+
options = {
73+
"id": "test_twitter_worker",
74+
"name": "Test Twitter Worker",
75+
"description": "An example Twitter Plugin for testing.",
76+
"credentials": {
77+
"apiKey": os.environ.get("TWITTER_API_KEY"),
78+
"apiSecretKey": os.environ.get("TWITTER_API_SECRET_KEY"),
79+
"accessToken": os.environ.get("TWITTER_ACCESS_TOKEN"),
80+
"accessTokenSecret": os.environ.get("TWITTER_ACCESS_TOKEN_SECRET"),
81+
},
82+
}
83+
# Initialize the TwitterPlugin with your options
84+
twitter_plugin = TwitterPlugin(options)
85+
86+
# Post a tweet
87+
post_tweet_fn = twitter_plugin.get_function('post_tweet')
88+
post_tweet_fn("Hello world!")
89+
```
90+
You can refer to `test_twitter.py` for more examples on how to call the twitter functions.

0 commit comments

Comments
 (0)