fix: Meta API hata yakalama ve Instagram entegrasyonu tamamen düzeltildi
This commit is contained in:
@@ -43,3 +43,27 @@ class XAPI:
|
||||
response = requests.post(self.TOKEN_URL, data=data, headers=headers, timeout=10)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def upload_media(self, access_token, media_data, mime_type="image/jpeg"):
|
||||
"""Upload media to X using API v1.1."""
|
||||
url = "https://upload.twitter.com/1.1/media/upload.json"
|
||||
headers = {'Authorization': f'Bearer {access_token}'}
|
||||
files = {'media': ('media_file', media_data, mime_type)}
|
||||
response = requests.post(url, headers=headers, files=files, timeout=30)
|
||||
response.raise_for_status()
|
||||
return response.json().get('media_id_string')
|
||||
|
||||
def create_tweet(self, access_token, text, media_ids=None):
|
||||
"""Post a tweet using API v2."""
|
||||
url = "https://api.twitter.com/2/tweets"
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
payload = {'text': text}
|
||||
if media_ids:
|
||||
payload['media'] = {'media_ids': media_ids}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=15)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
Reference in New Issue
Block a user