def get_access_token(): """Retrieve a previously stored access token, which gives this app permission to look at your data. This function currently expects an access token stored in a file. This will need to change once this app is hosted in the cloud. """ global ACCESS_TOKEN print("get_access_token, reporting for duty") try: ACCESS_TOKEN = open('out/facebook.access_token').read() except: print >> sys.stderr, "Could not find access token. Regnerating..." ACCESS_TOKEN=login()
from facebook__login import login try: ACCESS_TOKEN = open('out/facebook.access_token').read() except IOError, e: try: # If you pass in the access token from the Facebook app as a command line # parameter, be sure to wrap it in single quotes so that the shell # doesn't interpret any characters in it. You may also need to escape the # character ACCESS_TOKEN = sys.argv[1] except IndexError, e: print >> sys.stderr, \ "Could not either find access token in 'facebook.access_token' or parse args. Logging in..." ACCESS_TOKEN = login() BASE_URL = 'https://graph.facebook.com/me/home?access_token=' HTML_TEMPLATE = '../web_code/wp_cumulus/tagcloud_template.html' OUT_FILE = 'out/facebook.tag_cloud.html' NUM_PAGES = 5 MIN_FREQUENCY = 3 MIN_FONT_SIZE = 3 MAX_FONT_SIZE = 20 # Loop through the pages of connection data and build up messages url = BASE_URL + ACCESS_TOKEN messages = [] current_page = 0 while current_page < NUM_PAGES:
params = dict(queries=q, access_token=self.access_token, format='json') url = self.ENDPOINT + 'fql.multiquery' return self._fetch(url, params=params) # Sample usage... if __name__ == '__main__': try: ACCESS_TOKEN = open('out/facebook.access_token').read() Q = sys.argv[1] except IOError, e: try: # If you pass in the access token from the Facebook app as a command line # parameter, be sure to wrap it in single quotes so that the shell # doesn't interpret any characters in it. You may also need to escape # the # character ACCESS_TOKEN = sys.argv[1] Q = sys.argv[2] except IndexError, e: print >> sys.stderr, \ "Could not either find access token in 'facebook.access_token' or parse args." ACCESS_TOKEN = login() Q = sys.argv[1] fql = FQL(access_token=ACCESS_TOKEN) result = fql.query(Q) print json.dumps(result, indent=4)