Spaces:
Paused
Paused
Update func_facebook.py
Browse files- func_facebook.py +18 -7
func_facebook.py
CHANGED
@@ -20,19 +20,29 @@ def get_page_id(page_access_token):
|
|
20 |
url = f"{GRAPH_API_URL}/me"
|
21 |
params = {
|
22 |
"access_token": page_access_token,
|
23 |
-
"fields": "id,name,accounts"
|
24 |
}
|
25 |
response = requests.get(url, params=params)
|
26 |
data = response.json()
|
27 |
if 'error' in data:
|
28 |
log_message(f"Ошибка при получении ID страницы: {data['error']}")
|
29 |
return None
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def get_facebook_posts(token):
|
38 |
log_message("Получение постов.")
|
@@ -238,6 +248,7 @@ def hide_negative_comments(token):
|
|
238 |
|
239 |
comments_text = [comment['message'] for comment in comments]
|
240 |
sentiments = analyze_sentiment(comments_text)
|
|
|
241 |
negative_comments = [comment for comment, sentiment in zip(comments, sentiments) if sentiment['label'].lower() == 'negative']
|
242 |
|
243 |
hidden_comments = []
|
|
|
20 |
url = f"{GRAPH_API_URL}/me"
|
21 |
params = {
|
22 |
"access_token": page_access_token,
|
23 |
+
"fields": "id,name,accounts" # 'accounts' доступно только для User Access Token
|
24 |
}
|
25 |
response = requests.get(url, params=params)
|
26 |
data = response.json()
|
27 |
if 'error' in data:
|
28 |
log_message(f"Ошибка при получении ID страницы: {data['error']}")
|
29 |
return None
|
30 |
+
|
31 |
+
# Проверяем, существует ли поле 'accounts'
|
32 |
+
if 'accounts' in data:
|
33 |
+
accounts = data.get("accounts", {}).get("data", [])
|
34 |
+
if not accounts:
|
35 |
+
log_message("Нет доступных страниц для управления.")
|
36 |
+
return None
|
37 |
+
# Предполагаем, что первая страница является целевой; при необходимости измените логику
|
38 |
+
page_id = accounts[0].get("id")
|
39 |
+
log_message(f"Выбрана страница с ID: {page_id}")
|
40 |
+
return page_id
|
41 |
+
else:
|
42 |
+
# Если 'accounts' нет, предполагаем, что токен Page Access Token, и 'me' уже соответствует странице
|
43 |
+
page_id = data.get("id")
|
44 |
+
log_message(f"Используется Page Access Token. ID страницы: {page_id}")
|
45 |
+
return page_id
|
46 |
|
47 |
def get_facebook_posts(token):
|
48 |
log_message("Получение постов.")
|
|
|
248 |
|
249 |
comments_text = [comment['message'] for comment in comments]
|
250 |
sentiments = analyze_sentiment(comments_text)
|
251 |
+
# Фильтруем только негативные комментарии
|
252 |
negative_comments = [comment for comment, sentiment in zip(comments, sentiments) if sentiment['label'].lower() == 'negative']
|
253 |
|
254 |
hidden_comments = []
|