Skip to content

Commit fb590fe

Browse files
author
Jessica Garson
authored
Update create_tweet.py
1 parent c993f65 commit fb590fe

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Manage-Tweets/create_tweet.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
# export 'CONSUMER_KEY'='<your_consumer_key>'
77
# export 'CONSUMER_SECRET'='<your_consumer_secret>'
88

9-
consumer_key = "d7MEAv4mZhhCXmDl3IdKEJ9Lq"
10-
consumer_secret = "axzwg7UuUvXTi26D5L46TwX5h0mySP82euRIguFH6dnka1DCBN"
9+
consumer_key = os.environ.get("CONSUMER_KEY")
10+
consumer_secret = os.environ.get("CONSUMER_SECRET")
11+
12+
13+
# Be sure to replace tweet-id-to-delete with the id of the Tweet you wish to delete. The authenticated user must own the list in order to delete
14+
15+
id = "tweet-id-to-delete"
1116

12-
# 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.
13-
payload = {"text": "Hello world!"}
1417

1518
# Get request token
1619
request_token_url = "https://api.twitter.com/oauth/request_token"
@@ -56,13 +59,9 @@
5659
)
5760

5861
# Making the request
59-
response = oauth.post(
60-
"https://api.twitter.com/2/tweets",
61-
json=payload,
62-
headers={"x-des-apiservices": "staging1"},
63-
)
62+
response = oauth.delete("https://api.twitter.com/2/tweets/{}".format(id))
6463

65-
if response.status_code != 201:
64+
if response.status_code != 200:
6665
raise Exception(
6766
"Request returned an error: {} {}".format(response.status_code, response.text)
6867
)
@@ -71,4 +70,4 @@
7170

7271
# Saving the response as JSON
7372
json_response = response.json()
74-
print(json.dumps(json_response, indent=4, sort_keys=True))
73+
print(json_response)

0 commit comments

Comments
 (0)