#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    42
    Rep Power
    2

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    42
    Rep Power
    2
    Oh gosh, nobody can answer my question at all, I've tried so many ways but it still can not pass when that line has no ['message']
    I'm stuck can somebody at least suggest about how to skip the line or how to continue running by ignore an error value please..
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,856
    Rep Power
    481
    Run the process in a separate thread and kill it when a timer expires.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo