diff --git a/.gitignore b/.gitignore index 7c7cedc..de1e6e9 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,10 @@ build-iPhoneSimulator/ # Used by RuboCop. Remote config files pulled in from inherit_from directive. # .rubocop-https?--* + +# Virtual environments +venv/ +virtual/ + +# secrets +.env \ No newline at end of file diff --git a/Manage-Tweets/create_tweet.py b/Manage-Tweets/create_tweet.py index a8efc85..8e00696 100644 --- a/Manage-Tweets/create_tweet.py +++ b/Manage-Tweets/create_tweet.py @@ -1,26 +1,30 @@ from requests_oauthlib import OAuth1Session import os import json +from dotenv import load_dotenv +load_dotenv() # In your terminal please set your environment variables by running the following lines of code. -# export 'CONSUMER_KEY'='' -# export 'CONSUMER_SECRET'='' +# export 'api_key'='' +# export 'api_key_secret'='' -consumer_key = os.environ.get("CONSUMER_KEY") -consumer_secret = os.environ.get("CONSUMER_SECRET") + +api_key = os.environ["API_KEY"] +api_key_secret = os.environ["API_KEY_SECRET"] # Be sure to add replace the text of the with the text you wish to Tweet. You can also add parameters to post polls, quote Tweets, Tweet with reply settings, and Tweet to Super Followers in addition to other features. -payload = {"text": "Hello world!"} +payload = {"text": "This was tweeted from VScode in Python!"} # Get request token request_token_url = "https://api.twitter.com/oauth/request_token?oauth_callback=oob&x_auth_access_type=write" -oauth = OAuth1Session(consumer_key, client_secret=consumer_secret) +oauth = OAuth1Session(api_key +, client_secret=api_key_secret) try: fetch_response = oauth.fetch_request_token(request_token_url) except ValueError: print( - "There may have been an issue with the consumer_key or consumer_secret you entered." + "There may have been an issue with the API_KEY_SECRET or api_key_secret you entered." ) resource_owner_key = fetch_response.get("oauth_token") @@ -36,8 +40,8 @@ # Get the access token access_token_url = "https://api.twitter.com/oauth/access_token" oauth = OAuth1Session( - consumer_key, - client_secret=consumer_secret, + api_key, + client_secret=api_key_secret, resource_owner_key=resource_owner_key, resource_owner_secret=resource_owner_secret, verifier=verifier, @@ -49,8 +53,8 @@ # Make the request oauth = OAuth1Session( - consumer_key, - client_secret=consumer_secret, + api_key, + client_secret=api_key_secret, resource_owner_key=access_token, resource_owner_secret=access_token_secret, ) diff --git a/README.md b/README.md index 8da353e..ff9f5c6 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ Individual API features have folders where you can find examples of usage in sev In order to run the samples in this repository you will need to set up some environment variables. You can find your credentials and bearer token in the App inside of your Project in the [dashboard of the developer portal](https://developer.twitter.com/en/portal/projects-and-apps). -For OAuth 1.0a samples, you will need to export your consumer key and secret in your terminal. Be sure to replace `` and `` with your own credentials without the `< >`. +For OAuth 1.0a samples, you will need to export your consumer key and secret in your terminal. Be sure to replace `` and `` with your own credentials without the `< >`. ```bash -export CONSUMER_KEY='' -export CONSUMER_SECRET='' +export API_KEY='' +export API_KEY_SECRET='' ``` For samples which use bearer token authentication, you will need to export the bearer token. Be sure to replace `` with your own bearer token without the `< >`. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..87a7cd4 Binary files /dev/null and b/requirements.txt differ