Si vous pouvez obtenir et POST avec des requêtes, vous pouvez utiliser la plupart des méthodes fournies du côté API.
import requests
from requests_oauthlib import OAuth1
class Twitter():
def __init__(self, api_key):
self.OAuth = OAuth1(api_key["CONSUMER_KEY"], api_key["CONSUMER_SECRET"], api_key["ACCESS_TOKEN"], api_key["ACCESS_SECRET"])
def search_query(self, query, until=None, count=100): #Dans 1 semaine
url = 'https://api.twitter.com/1.1/search/tweets.json'
query += " exclude:nativeretweets filter:media"
params = {'q': query, 'result_type': 'mixed', 'until': until, 'count': count, 'include_entities': True}
request = requests.get(url, params=params, auth=self.OAuth)
requestJson = json.loads(request.text)
return requestJson
def update_status(self, status, reply_id=None):
url = 'https://api.twitter.com/1.1/statuses/update.json'
params = {'status': status, 'in_reply_to_status_id': reply_id}
request = requests.post(url, params=params, auth=self.OAuth)
def get_my_tweet(self, count=1, screen_name=screen_name):
url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'
params = {'count': count, 'screen_name': screen_name}
request = requests.get(url, params=params, auth=self.OAuth)
requestJson = json.loads(request.text)
return requestJson
def get_tweets_of_user(self, count=100, screen_name=None):
url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'
params = {'count': count, 'screen_name': screen_name}
request = requests.get(url, params=params, auth=self.OAuth)
requestJson = json.loads(request.text)
return requestJson
def update_profile(self, profile_url):
url = 'https://api.twitter.com/1.1/account/update_profile.json'
params = {'url': profile_url}
request = requests.post(url, params=params, auth=self.OAuth)
def retweet(self, id_):
url = 'https://api.twitter.com/1.1/statuses/retweet/{}.json'.format(id_)
request = requests.post(url, auth=self.OAuth)
def delete_tweet(self, id_):
url = "https://api.twitter.com/1.1/statuses/destroy/{}.json".format(id_)
request = requests.post(url, auth=self.OAuth)
def follow(self, user_id):
url = 'https://api.twitter.com/1.1/friendships/create.json'
params = {'user_id': user_id}
request = requests.post(url, params=params, auth=self.OAuth)
Recommended Posts