Twitter Plugin for Python SDK for GAME by Virtuals
Project description
Twitter Plugin for GAME SDK
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.
Installation
From this directory (twitter), run the installation:
poetry install
Usage
- Choose one of the 2 options to initialise the Twitter plugin
GameTwitterPlugin- This allows one to leverage GAME's X enterprise API credentials (i.e. higher rate limits)
TwitterPlugin- This allows one to use their own X API credentials
- Initialise plugin objects, run set-up scripts and use plugin functions
-
GameTwitterPlugin- To get the access token to us this plugin, run the following command
poetry run twitter-plugin-gamesdk auth -k <GAME_API_KEY>
You will see the following output:Waiting for authentication... Visit the following URL to authenticate: 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
After authenticating, you will receive the following message:Authenticated! Here's your access token: apx-<xxx>
- Set the access token as an environment variable called
GAME_TWITTER_ACCESS_TOKEN(e.g. using a.bashrcor a.zshrcfile): - Import and initialize the plugin to use in your worker:
import os from twitter_plugin_gamesdk.game_twitter_plugin import GameTwitterPlugin # Define your options with the necessary credentials options = { "id": "test_game_twitter_plugin", "name": "Test GAME Twitter Plugin", "description": "An example GAME Twitter Plugin for testing.", "credentials": { "gameTwitterAccessToken": os.environ.get("GAME_TWITTER_ACCESS_TOKEN") }, } # Initialize the TwitterPlugin with your options game_twitter_plugin = GameTwitterPlugin(options) # Post a tweet post_tweet_fn = game_twitter_plugin.get_function('post_tweet') post_tweet_fn("Hello world!")
You can refer toexamples/test_game_twitter.pyfor 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.
- To get the access token to us this plugin, run the following command
-
TwitterPlugin- If you don't already have one, create a X (twitter) account and navigate to the developer portal.
- Create a project app, generate the following credentials and set the following environment variables (e.g. using a
.bashrcor a.zshrcfile):TWITTER_API_KEYTWITTER_API_SECRET_KEYTWITTER_ACCESS_TOKENTWITTER_ACCESS_TOKEN_SECRET
- Import and initialize the plugin to use in your worker:
import os from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin # Define your options with the necessary credentials options = { "id": "test_twitter_worker", "name": "Test Twitter Worker", "description": "An example Twitter Plugin for testing.", "credentials": { "apiKey": os.environ.get("TWITTER_API_KEY"), "apiSecretKey": os.environ.get("TWITTER_API_SECRET_KEY"), "accessToken": os.environ.get("TWITTER_ACCESS_TOKEN"), "accessTokenSecret": os.environ.get("TWITTER_ACCESS_TOKEN_SECRET"), }, } # Initialize the TwitterPlugin with your options twitter_plugin = TwitterPlugin(options) # Post a tweet post_tweet_fn = twitter_plugin.get_function('post_tweet') post_tweet_fn("Hello world!")
You can refer toexamples/test_twitter.pyfor more examples on how to call the twitter functions.
-
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twitter_plugin_gamesdk-0.2.3.tar.gz.
File metadata
- Download URL: twitter_plugin_gamesdk-0.2.3.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc49d0a28529c599e338420c43798eedb4e390c2f09a1defbd81b1ebcf1c781d
|
|
| MD5 |
4adedab8487c9f3139bf73a08f68d34f
|
|
| BLAKE2b-256 |
18f4ac1981b7c73842f24152ff566dccf0a8f2cfb6a622f863f80393eae884e1
|
File details
Details for the file twitter_plugin_gamesdk-0.2.3-py3-none-any.whl.
File metadata
- Download URL: twitter_plugin_gamesdk-0.2.3-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3b07efb7b0a032efcface6c3266ab59c62a5f9709a5ef36e7ad0a05b0c5a61b
|
|
| MD5 |
060a3094b1618aa512d489eb31e6562c
|
|
| BLAKE2b-256 |
f44b02e347b32e5938b0002e5338106d9e69ee23f63eb049f292b57fc00fe458
|