Last active
September 17, 2019 02:29
-
-
Save thejsj/dc66e2b31906cb12c4ad322dea88fda9 to your computer and use it in GitHub Desktop.
Favoriting a Tweet from Socialstream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import requests | |
SOCIALSTREAM_API_KEY = "" | |
CAMPAIGN_ID = "" | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET = "" | |
ACCESS_TOKEN = "" | |
ACCESS_TOKEN_SECRET = "" | |
# Authenticate to Twitter | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
def main(): | |
api = tweepy.API(auth) | |
try: | |
api.verify_credentials() | |
print("Authentication OK") | |
except Exception: | |
print("Error during authentication") | |
data = {"count": 1, "include_accepted": True} | |
headers = {"Authorization": "Bearer {}".format(SOCIALSTREAM_API_KEY)} | |
r = requests.post("https://app.socialstream.ai/api/v1/campaign/{}/lead/".format(CAMPAIGN_ID), json=data, headers=headers) | |
response = r.json() | |
if "data" not in response or type(response.get("data", None)) is not list: | |
print("Error in aquiring data") | |
return | |
lead = response["data"][0] | |
if lead["source"] != "twitter": | |
print("Not Twitter") | |
return True | |
external_id = lead["json"].get("id") | |
print("Create favorite") | |
api.create_favorite(external_id) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment