Unable to retrieve search results from server side : Facebook Graph API usig Python

Posted by DjangoRocks on Stack Overflow See other posts from Stack Overflow or by DjangoRocks
Published on 2011-01-10T06:46:00Z Indexed on 2011/01/10 12:53 UTC
Read the original article Hit count: 232

Filed under:
|

Hi all,

I'm doing some simple Python + FB Graph training on my own, and I faced a weird problem:

import time
import sys
import urllib2
import urllib
from json import loads

base_url = "https://graph.facebook.com/search?q="
post_id = None
post_type = None
user_id = None 
message = None
created_time = None

def doit(hour):
    page = 1
    search_term = "\"Plastic Planet\""
    encoded_search_term = urllib.quote(search_term)
    print encoded_search_term
    type="&type=post"
    url = "%s%s%s" % (base_url,encoded_search_term,type)
    print url
    while(1):

        try:
            response = urllib2.urlopen(url)
        except urllib2.HTTPError, e:
            print e
        finally:
            pass   

        content = response.read()
        content = loads(content)

        print "=================================="
        for c in content["data"]:
            print c
            print "****************************************"

        try:
            content["paging"]
            print "current URL"
            print url
            print "next page!------------"
            url = content["paging"]["next"]
            print url
        except:
            pass
        finally:
            pass

        """
        print "new URL is ======================="
        print url
        print "==================================" 
        """
        print url

What I'm trying to do here is to automatically page through the search results, but trying for content["paging"]["next"]

But the weird thing is that no data is returned; i received the following:

{"data":[]}

Even in the very first loop.

But when i copied the URL into a browser, a lot of results were returned.

I've also tried a version with my access token and th same thing happens.

Can anyone enlighten me?

+++++++++++++++++++EDITED and SIMPLIFIED++++++++++++++++++

ok thanks to TryPyPy, here's the simplified and edited version of my previous question:

Why is that:

   import urllib2
       url = "https://graph.facebook.com/searchq=%22Plastic+Planet%22&type=post&limit=25&until=2010-12-29T19%3A54%3A56%2B0000"
       response = urllib2.urlopen(url)
       print response.read() 

result in {"data":[]} ?

But the same url produces a lot of data in a browser?

Anyone?

Best Regards.

© Stack Overflow or respective owner

Related posts about python

Related posts about facebook-graph-api