python - facebook page info using Graph Api 2.2 -
i have unique id of 1000 facebook pages inside google spreadsheet . want crawl pages info (likes, email etc) should do? cannot run search query in browser , run script. plz detailed possible. thank u :)
i tried make python script works 1st entry only.
import urllib url2 import json f=open('ids.txt') in f: url="http://graph.facebook.com/"+str(int(i))+"?fields=likes" data = url2.urlopen(url).read() print data data2=json.loads(data) print "number of likes on page id "+str(data2["id"])+" has "+str(data2["likes"])+" likes !" f.close()
the ids.txt file contains id of facebook pages.
1 493343230696447 2 1767379894975 3 122116091270024 4 545044065615713
a file object line iterator, not word iterator. need change:
for in f: url="http://graph.facebook.com/"+str(int(i))+"?fields=likes"
to:
for in f: # holds line, not index index, page_id = i.strip().split()[:2] url="http://graph.facebook.com/"+page_id+"?fields=likes" # ...
this way split line, after removing line break ('\n'
), index
, page_id
, separately.
there no need cast page_id
string integer , string.
Comments
Post a Comment