Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change consumer_key to api_key in readme #134

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 15 additions & 11 deletions Manage-Tweets/create_tweet.py
Original file line number Diff line number Diff line change
@@ -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'='<your_consumer_key>'
# export 'CONSUMER_SECRET'='<your_consumer_secret>'
# export 'api_key'='<your_API_KEY>'
# export 'api_key_secret'='<your_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")
Expand All @@ -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,
Expand All @@ -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,
)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<your_consumer_key>` and `<your_consumer_secret>` 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 `<your_api_key>` and `<your_api_key_secret>` with your own credentials without the `< >`.

```bash
export CONSUMER_KEY='<your_consumer_key>'
export CONSUMER_SECRET='<your_consumer_secret>'
export API_KEY='<your_api_key>'
export API_KEY_SECRET='<your_api_key_secret>'
```

For samples which use bearer token authentication, you will need to export the bearer token. Be sure to replace `<your_bearer_token>` with your own bearer token without the `< >`.
Expand Down
Binary file added requirements.txt
Binary file not shown.
Loading