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
The Twitter plugin can be initialized in one of two ways:
-
Using GAME's X enterprise API credentials (higher rate limits)
-
To get the access token for this option, 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.twitter_plugin import TwitterPlugin # Define your options with the necessary credentials options = { "credentials": { "gameTwitterAccessToken": os.environ.get("GAME_TWITTER_ACCESS_TOKEN") }, } # 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!")
-
-
Using your own X API credentials
-
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 them as environment variables (e.g. using a
.bashrcor a.zshrcfile):TWITTER_BEARER_TOKENTWITTER_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 = { "credentials": { "bearerToken": os.environ.get("TWITTER_BEARER_TOKEN"), "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.twitter_client.create_tweet post_tweet_fn(text="Hello world! This is a test tweet from the Twitter Plugin!")
-
For detailed documentation on each function's parameters and usage, please refer to the Tweepy Client Documentation.
Example usage:
You can refer to the example files in the examples directory for 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.6.tar.gz.
File metadata
- Download URL: twitter_plugin_gamesdk-0.2.6.tar.gz
- Upload date:
- Size: 4.6 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 |
a6168e68b8b70cd93725c178907827920a575d4f92450547b201011960f5c39f
|
|
| MD5 |
a8689ad9bf8b19357b6d3241b9f3aa68
|
|
| BLAKE2b-256 |
667ddec28aabede0d77b98091ea0449bf735498e3243fffb1b5a08407c95ac4f
|
File details
Details for the file twitter_plugin_gamesdk-0.2.6-py3-none-any.whl.
File metadata
- Download URL: twitter_plugin_gamesdk-0.2.6-py3-none-any.whl
- Upload date:
- Size: 5.9 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 |
bb092592ad4ce318e1141d77fa8ab52ce798c632fc144ab18ab7d7390ef19149
|
|
| MD5 |
c7fb4652f5a988c6656ccbb790465066
|
|
| BLAKE2b-256 |
7fafd369eff7d5213d4cca06bdfc7a4ccb718dfdf9c36f251abf6f52a9a313d3
|