我使用python从Facebook GraphAPI中提取了一些数据并将其保存到变量中。 API返回JSON,它在Python中保存为嵌套字典。这就是API中的数据在浏览器中的样子。
我希望mongoDB以FB API返回的健全的JSON格式存储数据。这可能吗?
代码:
import facebook
graph = facebook.GraphAPI(access_token='my_token', version='2.7')
post = graph.get_object(id='me/friends', fields='feed{message,story,story_tags,created_time,id,message_tags},posts{message,story,story_tags,message_tags,created_time,id},name')
print(post)
请帮助。
答案 0 :(得分:-1)
是:
from pymongo import MongoClient
db = MongoClient().test
db.collection.insert_one(post)
The PyMongo tutorial是学习Python和MongoDB的好方法。