def get_extended_access_token(access_token, application_id, application_secret_key):
    """
    Get an extended OAuth access token.

    :param access_token: A string describing an OAuth access token.
    :param application_id: An integer describing the Facebook application's ID.
    :param application_secret_key: A string describing the Facebook application's secret key.

    Returns a tuple with a string describing the extended access token and a datetime instance
    describing when it expires.
    """
    graph = GraphAPI()

    response = graph.get(
        path='oauth/access_token',
        client_id=application_id,
        client_secret=application_secret_key,
        grant_type='fb_exchange_token',
        fb_exchange_token=access_token
    )

    components = parse_qs(response)

    token = components['access_token'][0]
    expires_at = datetime.now() + timedelta(seconds=int(components['expires'][0]))

    return token, expires_at
    def authenticate(self, session):
        api = GraphAPI(session.access_token)
        fql = '''
        SELECT uid, email, first_name, last_name, pic_big, pic, pic_small 
        FROM user WHERE uid = me()'''
        profile = api.get(path='fql', fql=fql)[0]
        user = self.save_user(profile)
        token = self.save_token(session, user)

        return user
Exemple #3
0
def async_test(request):
    api = GraphAPI(request.access_token)
    task1 = {'id': 'significant_other',
             'fql': '''select name, uid from user where uid in 
             (select significant_other_id from user where uid=me())'''}

    task2 = {'id': 'family_birthdates',
             'fql': '''select name, birthday_date, relationship_status, 
             significant_other_id, family from user where uid = me()'''}

    tasks = [task1, task2]
    api.start_async_tasks(tasks)
    processed_tasks = api.tasks
    logging.debug(processed_tasks)

    return HttpResponse(simplejson.dumps(processed_tasks))
def get_application_access_token(application_id, application_secret_key):
    """
    Get an OAuth access token for the given application.

    :param application_id: An integer describing a Facebook application's ID.
    :param application_secret_key: A string describing a Facebook application's secret key.
    """
    graph = GraphAPI()

    response = graph.get(
        path='oauth/access_token',
        client_id=application_id,
        client_secret=application_secret_key,
        grant_type='client_credentials'
    )

    data = parse_qs(response)

    try:
        return data['access_token'][0]
    except KeyError:
        raise GraphAPI.FacebookError('No access token given')
Exemple #5
0
class Friends(ApiClient):
    ''' 'This class will construct HTTP requests to obtain friends related information'''
    def __init__(self):
        super(Friends, self).__init__()
        self.graph_util = GraphAPI(access_token=self.token, api_version="2.10")

    def get_all_friends(self):
        '''  
        	This method returns all friends of a given access token

        	Returns:
	    List of IDs of all friends
        '''
        graph = self.graph_util.get(endpoint="me/friends",
                                    params={
                                        "debug": "all",
                                        "format": "json",
                                        "suppress_http_code": "1"
                                    })
        for friend in friends['data']:
            print("{} has id {}".format(friend['name'].encode('utf-8'),
                                        friend['id']))
Exemple #6
0
 def __init__(self):
     super(Friends, self).__init__()
     self.graph_util = GraphAPI(access_token=self.token, api_version="2.10")