def _update_access_token(user, graph):
    profile = try_get_profile(user)
    model_or_profile = get_instance_for_attribute(
        user, profile, 'access_token')
    # store the access token for later usage if the profile model supports it
    if model_or_profile:
        # update if not equal to the current token
        new_token = graph.access_token != model_or_profile.access_token
        token_message = 'a new' if new_token else 'the same'
        logger.info(
            'found %s token %s', token_message, graph.access_token[:10])
        if new_token:
            logger.info('access token changed, updating now')
            model_or_profile.update_access_token(graph.access_token)
            model_or_profile.save()
            # see if we can extend the access token
            # this runs in a task, after extending the token we fire an event
            model_or_profile.extend_access_token()
Conditionally updates the access token in the database
dataset/ETHPy150Open tschellenbach/Django-facebook/django_facebook/connect.py/_update_access_token