def main(): app_id = 1486791588264932 app_secret = "93595d85e282ce2bb395a21c92139631" oath_access_token = utils.get_application_access_token(app_id, app_secret) token = "CAACEdEose0cBAHdKj7pO0wWcQ1l7Nk5SXOUZAWdIEOZCvFg6JuL8IRJQcTJZBg GpNgoO5M2d3nZBYOhOdnDgn9gJc9mZCk8bC9N5yIMAEVpZAWX8pgIv CSZCGWu6vkfX5I1VDCfkyLHaKkxpgLOyTsnOCHuWkiBrjlW5dN1IHNLmZ C168XZBMJIc1r5UA7ssNZAUhJPsbNzaR1rer93oSuQA4kZAfNIjGCp95IZD" print oath_access_token graph = GraphAPI(token) for friendlist in graph.get('me/friendlists/')["data"]: print for friend in graph.get( friendlist["id"] + "/members" )["data"]: print friend["name"] try: print len( graph.get(friend["id"] + "/friends/")["data"] ) print len(frnd_friendlist) except : print 0
def __init__(self): app_id = Config.get_value('authentication', 'app_id') app_secret = Config.get_value('authentication', 'app_secret') self.oath_access_token = None if self.oath_access_token is None: self.oath_access_token = utils.get_application_access_token(app_id, app_secret) self.graph = GraphAPI(self.oath_access_token)
def get_fb_access_token(): app_id = FACEBOOK_ID # must be integer app_secret = FACEBOOK_SECRET oath_access_token = utils.get_application_access_token(app_id, app_secret) print 'this is your access token:' print '\t'+ str(oath_access_token) return oath_access_token
def get_fb_access_token(): app_id = FACEBOOK_ID # must be integer app_secret = FACEBOOK_SECRET oath_access_token = utils.get_application_access_token(app_id, app_secret) print 'this is your access token:' print '\t' + str(oath_access_token) return oath_access_token
def for_application(self, id, secret_key): """ Initialize GraphAPI with an OAuth access token for an application. :param id: An integer describing a Facebook application. :param secret_key: A String describing the Facebook application's secret key. """ from facepy.utils import get_application_access_token return GraphAPI(get_application_access_token(id, secret_key))
def process_posts(containers): """ Do facebook requests for the posts urls and update the comment count """ APP_ID = getattr(settings, 'FACEBOOK_APP_ID', None) API_SECRET = getattr(settings, 'FACEBOOK_API_SECRET', None) if not APP_ID and API_SECRET: raise ImproperlyConfigured('You must have an FACEBOOK_APP_ID and a ' ' FACEBOOK_API_SECRET in your settings.py') token = get_application_access_token(APP_ID, API_SECRET) graph = GraphAPI(token) # print "Queue:", posts.count() for container in container.iterator(): # print "Processing:", post.slug comment_data = get_top_comment_info( graph, container.get_http_absolute_url() ) # print "get data", comment_data if comment_data.get('profile_name'): comment_count = comment_data.get('comment_count') comment_text = comment_data.get('comment_text') profile_name = comment_data.get('profile_name') comment_time = comment_data.get('comment_time') # TODO: Use get_or_create try: top = TopComment.objects.get(container=container) top.comment_count = comment_count top.comment_text = comment_text top.profile_name = profile_name top.date_added = comment_time top.save() except TopComment.DoesNotExist: # TODO: save each comment in a separate model # retrieve only latest published TopComment.objects.create( container=container, comment_count=comment_count, profile_name=profile_name, comment_text=comment_text, date_added=comment_time, user=container.user, site=container.site, published=True )
print e print "Database `facebookindex` already exists" try: r.db('facebookindex').table_create("feed").run() except Exception as e: print e print "Table `feed` already exists" group_id = sys.argv[1] backfill = False if len(sys.argv) > 1: backfill = sys.argv[2] == "backfill" access_token = get_application_access_token(APPLICATION_ID, APPLICATION_SECRET) graph = GraphAPI(access_token) if backfill: print "BACKFILLING" pages = graph.get("%s/feed" % group_id, page=True, retry=3, limit=1) else: print "DOING ONLY PAST DAY" yesterday = datetime.datetime.now() - datetime.timedelta(days=1) yesterday_beginning = datetime.datetime(yesterday.year, yesterday.month, yesterday.day, 0, 0, 0, 0) yesterday_beginning_time = int( time.mktime(yesterday_beginning.timetuple())) yesterday_end = datetime.datetime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59, 999) yesterday_end_time = int(time.mktime(yesterday_end.timetuple()))
def get_api_connection(): access_token = utils.get_application_access_token(settings.FACEBOOK_APP_ID, settings.FACEBOOK_APP_SECRET) # Create GraphAPI instance to interact with Facebook API return GraphAPI(access_token)
#reading file "social_monitors_settings.ini" import ConfigParser config=ConfigParser.ConfigParser() config.read("social_monitors_settings.ini") # ztreamy variables pilot = config.get("streams","streams_facebook") ztreamyUrl = config.get("global","ztreamy_server") + pilot +"/publish" # variables: frequency = 10000 # Not used # Configure facebook application_id = config.get('facebook','app_id') application_secret_key = config.get('facebook','app_secret') access_token = utils.get_application_access_token(application_id, application_secret_key) # TODO: If we want to access private pages or groups, a bot must be used graph = GraphAPI(access_token) fb_pages = config.get('facebook','fb_pages').split(",") # The facebook message has the following properties # print message['message'].encode('utf-8') # print message['from']['name'].encode('utf-8') # print message['created_time'] # print message['id'] def parse_comment(page_name,comment): logging.info("Incoming comment from page " + page_name + ". Message: " + json.dumps(comment)) json_to_keep = fix_json_format("FB_CMT "+comment['message'], comment['created_time'], page_name+":"+comment['from']['name'], comment['id']) json_to_keep["originalMessage"] = json.dumps(comment).replace("\"","#quot#") return json_to_keep
from facepy import utils app_id = 1476062702607954 # must be integer app_secret = "dcaa2a6dd1a5c18e068d05341b572395" oath_access_token = utils.get_application_access_token(app_id, app_secret) print "token = ",oath_access_token
Retrieves app id and app secret from a file in the same directory as this script. First line must be app ID. The Facebook graph app must have user_managed_groups. Second line must be the app secret. Returns list with the app id and app secret in the order read in file """ secret = open("secret.txt", 'r') return [line.strip() for line in secret] # get app ID and app secret idAndSecret = getInfo() # tuple (ID, secret) # get access token (token, expiration) accessTokenInfo = utils.get_application_access_token(idAndSecret[0], idAndSecret[1]) graph = GraphAPI( accessTokenInfo[0]) # create graph object to GET, post or search # skim the feed and see if there is a user post in a group def fetchLatestFeed(user, group): """ Skims the front-page of the recent activity section of the feed to see if there is a new post by given user. Parameters: user, a str for the ID of the user to search for group, a str for the ID of the group to be searching for Returns: The permalink of the posts from user in group
def __init__(self): app_id = config.app_id_facebook app_secret = config.app_secret_facebook access_token = utils.get_application_access_token(app_id, app_secret) self.graphAPI = GraphAPI(access_token)
def get_aut_token(app_id, app_secred): # not log user token return utils.get_application_access_token(app_id, app_secred)
mega_list.append(jj) duration = (time.time() - start) / float(60) print("Time:" + str(duration) + 'min') with open(onoma, 'w') as f: json.dump(mega_list, f) return mega_list def pros(i): st = s(i['id'], access_token) comm = c(i['id'], access_token, 1) d = {} d['post'] = i d['statistics'] = st d['comments'] = comm return d """ check time of last element ff[0]['post']['created_time'] """ if __name__ == '__main__': page_id = input("Give group id: \n") global access_token app_id = int(input("Give app id: \n")) app_secret = ("Give app secret: \n") access_token = utils.get_application_access_token(app_id, app_secret)[0] onoma = input("Give name of file to save data: \n") fun_page(page_id, onoma)
def get_access_token(app_id, app_secret): access_token = utils.get_application_access_token(app_id, app_secret) #extended_access_token = utils.get_extended_access_token(access_token, #app_id, app_secret) return access_token
def get_access_token(): app_id = 431502770337118 # must be integer app_secret = "da89270e98a88a1a56fd9a71b1985b95" access_token = utils.get_application_access_token(app_id, app_secret) return access_token
def get_aut_token(app_id, app_secred): return utils.get_application_access_token(app_id, app_secred)