
November 27th, 2012, 06:29 PM
|
|
Contributing User
|
|
Join Date: Nov 2012
Posts: 35
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
|
|
|
About Python for facebook API [parsing messagefile]
Hello,
I'm newbie in Python and I'm now learning about Facebook API in Python. I'm trying to parse the message data from facebook which I can do query from
https://graph.facebook.com/search?q=Query&type=post&access_token=
Frist, I parse the data from url and I load url into json format, then I retreive data as ['data']
but the problem is when I fetch data from query ['message'], it works but it got crashed because the next line has not "message" in that query. My question is I want to fetch lots of data but I don't want my application to get stopped when it found that the next line has no "message" on that query, what should I do?
Here's my code:
Code:
url ='https://graph.facebook.com/search?q=Query&type=post&access_token=&limit=50'
response = urllib.urlopen(url).read()
data = json.loads(response)
results = data['data']
for i in range(50):
print results[i]['message']+':'+'\n'
Assume that when the data goes to i=9, and that line has no query name 'message', my application will stop at that line and not continue to run until it finished. If you know something about my problem, please help me.
I'm looking forward to see your answer,
Thank you so much
|