Я пишу код, необходимый для этапа проверки, и тестирую его на своей странице. В настоящее время я могу получить все необходимые данные, кроме:
- Количества/типа различных реакций (Нравится, Любовь, Обнять и т. д.) каждое сообщение.
- Тип сообщения (с фото, видео, только текст, ссылка и т. д.).
Ниже приведен код, который я написал. Я знаю, что это не очень красиво, я все еще учусь. Я все еще кое-что тестирую, в конечном итоге все данные будут помещены в фрейм данных.
Заранее благодарю вас за внимание и любую помощь, которую вы можете мне оказать.
token=""
def export_post_booster(token):
page_id=""
graph = facebook.GraphAPI(token)
posts = graph.request(page_id+'/posts')
count=1
while "paging" in posts:
for post in posts["data"]:
shares = graph.request(post["id"]+"?fields=shares")
reacts = graph.request(post["id"]+"/likes?summary=True")
coms = graph.request(post["id"]+"?fields=comments.summary(true)")
none = graph.request(post["id"]+"?fields=reactions.type(NONE).summary(true)")
like = graph.request(post["id"]+"?fields=reactions.type(LIKE).summary(true)")
love = graph.request(post["id"]+"?fields=reactions.type(LOVE).summary(true)")
wow = graph.request(post["id"]+"?fields=reactions.type(WOW).summary(true)")
haha = graph.request(post["id"]+"?fields=reactions.type(HAHA).summary(true)")
sad = graph.request(post["id"]+"?fields=reactions.type(SAD).summary(true)")
angry = graph.request(post["id"]+"?fields=reactions.type(ANGRY).summary(true)")
coms = graph.request(post["id"]+"?fields=comments.summary(true)")
print("----------------",count,"----------------")
print("time : ",post["created_time"])
print("id :",post["id"],"\n")
if "message" in post:
print("Text Post : ",post["message"])
else:
print("Text Post : NULL")
try:
print("shares :",shares["shares"]["count"])
except:
print("shares : 0")
try:
print("likes : ",reacts["summary"]["total_count"])
except:
print("likes : 0")
try:
print("none : ",none["summary"]["total_count"])
except:
print("none : 0")
try:
print("love : ",love["summary"]["total_count"])
except:
print("love : 0")
try:
print("wow : ",wow["summary"]["total_count"])
except:
print("wow : 0")
try:
print("sad : ",sad["summary"]["total_count"])
except:
print("sad : 0")
try:
print("love : ",love["summary"]["total_count"])
except:
print("love : 0")
try:
print("angry : ",angry["summary"]["total_count"])
except:
print("angry : 0")
for i in range(0, len(coms["comments"]["data"])):
print(">
Подробнее здесь: https://stackoverflow.com/questions/721 ... -graph-api