-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_post.py
51 lines (34 loc) · 1.31 KB
/
content_post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import requests
from dotenv import load_dotenv
load_dotenv()
class Post:
def __init__(self):
self.access_token = os.getenv('access_token')
self.ig_user_id = os.getenv("ig_user_id")
def create_container(self, image_url):
url = f"https://graph.facebook.com/{self.ig_user_id}/media"
caption = "#hello"
payload = {
"image_url": image_url,
"caption": caption,
"access_token": self.access_token
}
response = requests.post(url, data=payload)
if response.status_code == 200:
print("Container created successfully:", response.json())
return response.json()['id']
else:
print("Failed to create the container:", response.status_code, response.text)
def publish_container(self,creation_id):
# URL for publishing media
url = f"https://graph.facebook.com/{self.ig_user_id}/media_publish"
payload = {
"creation_id": creation_id,
"access_token": self.access_token
}
response = requests.post(url, data=payload)
if response.status_code == 200:
print("Media published successfully:", response.json())
else:
print("Failed to publish media:", response.status_code, response.text)