Skip to main content

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

  1. 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
  2. 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 .bashrc or a .zshrc file):
      • 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 to examples/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.
    • 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 .bashrc or a .zshrc file):
        • TWITTER_API_KEY
        • TWITTER_API_SECRET_KEY
        • TWITTER_ACCESS_TOKEN
        • TWITTER_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 to examples/test_twitter.py for more examples on how to call the twitter functions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twitter_plugin_gamesdk-0.2.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twitter_plugin_gamesdk-0.2.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file twitter_plugin_gamesdk-0.2.2.tar.gz.

File metadata

  • Download URL: twitter_plugin_gamesdk-0.2.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.3.0

File hashes

Hashes for twitter_plugin_gamesdk-0.2.2.tar.gz
Algorithm Hash digest
SHA256 9671cecedf240b5037b17480778c620d54d406b8eee4bb54d53d7e68dd6bfc07
MD5 f1aa3661bb05d4fa204d301f2919a1de
BLAKE2b-256 f8ea3be66fdd99cfbd1cb95979a78c7122ce779f596ce9dd634668de318d1395

See more details on using hashes here.

File details

Details for the file twitter_plugin_gamesdk-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for twitter_plugin_gamesdk-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eee3df753b91fb8a58373dcf53ca312dee5a4a3a4ad040cfb3b35c34c0f7f8d5
MD5 3bc798f16e2625d6f017985771b86bca
BLAKE2b-256 86dfe5de6141251bf6a3fffb5ae4239ad53db3ebd159e735cc6654ce426cb19f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page