Skip to content

Instantly share code, notes, and snippets.

@ranman
Created November 3, 2017 15:54
Show Gist options
  • Save ranman/35a4b91cdfb32b4f1b08629f9e8a6ded to your computer and use it in GitHub Desktop.
Save ranman/35a4b91cdfb32b4f1b08629f9e8a6ded to your computer and use it in GitHub Desktop.
from requests_oauthlib import OAuth1Session
import os
CONSUMER_KEY = os.getenv("CONSUMER_KEY")
CONSUMER_SECRET = os.getenv("CONSUMER_SECRET")
ACCESS_KEY = os.getenv("ACCESS_KEY")
ACCESS_SECRET = os.getenv("ACCESS_SECRET")
twitter = OAuth1Session(
CONSUMER_KEY,
client_secret=CONSUMER_SECRET,
resource_owner_key=ACCESS_KEY,
resource_owner_secret=ACCESS_SECRET
)
base_url = "https://api.twitter.com/1.1/"
r = twitter.post(base_url+"account_activity/webhooks.json", params={'url': "https://api.ranman.com/twitter/webhook"})
r.raise_for_status()
webhook_id = r.json()['id']
resp = twitter.post(base_url+"account_activity/webhooks/{}/subscriptions.json".format(webhook_id))
print(resp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment