import json
import time
import urllib
from pymongo import MongoClient
from facepy import GraphAPI
access_token = 'EAACEdEose0cBAKrXodSbgJM32aihWYeFwnm3X8i2CPB7Pn4L2fujnNDc49pGwuV4pqccHxsX2ooudEVRGRAGe7mDZAB0mlZCGFO12cW78klPGjVeanTaJjwZCuNek8BsQRisUeUh7CijjOyTReVybj0EeZAZBBpf0Y099uE9pBgZDZD'
graph = GraphAPI(access_token,version= '2.8')
def counts():
posts= "no likes"
client = MongoClient()
db = client.fb
collection = db.check
query = db.posts.find()
for q in query:
liker_id = "null"
liker_name = "null"
likes = "no likes in the post"
id = q['post_id']
response=graph.get(id+'?fields=likes.summary(true),comments.summary(true),shares')
if 'likes' in response:
for d in response['likes']['data']:
liker_id = d['id']
liker_name = d['name']
for i in liker_id:
posts = {"id":[liker_id]}
post = {"post_id":id,"likes":posts}
print post
counts()
{'post_id': u'256015257837672_1017155801723610', 'likes': {'id': [u'905803702763261']}}
{'post_id': u'256015257837672_1016685905103933', 'likes': {'id': [u'808269765904912']}}
I AM GETTING ONLY THE LAST LIKER_ID IN THE OUTPUT BUT I WANT TO STORE ALL THE LIKER_ID IN THAT LIKES SECTION PLEASE HELP ME WITH THIS THANKING YOU
It can simply done by appending the post as an array so it will get all the data in an array