Esempio n. 1
0
def get_friends(user_id, fields):
    """ Вернуть данных о друзьях пользователя

    :param user_id: идентификатор пользователя, список друзей которого нужно получить
    :param fields: список полей, которые нужно получить для каждого пользователя
    """
    assert isinstance(user_id, int), "user_id must be positive integer"
    assert isinstance(fields, str), "fields must be string"
    assert user_id > 0, "user_id must be positive integer"

    domain = "https://api.vk.com/method"
    access_token = config.VK_CONFIG['access_token']
    user_id = user_id

    query_params = {
        'domain': domain,
        'access_token': access_token,
        'user_id': user_id,
        'fields': fields
    }

    query = "{domain}/friends.get?access_token={access_token}&user_id={user_id}&fields={fields}&v=5.53".format(**query_params)
    response = get(query).json()
    try:
        response = response['response']['items']
    except:
        return []
    for num, friend in enumerate(response):
        user = User(id= friend['id'], first_name=friend['first_name'], last_name=friend['last_name'], online=friend['online'])
        try:
            user.bdate = friend['bdate']
        except:
            pass
        response[num] = user
    return response
Esempio n. 2
0
def get_friends(user_id, fields):
    assert isinstance(user_id, int), "user_id must be positive integer"
    assert isinstance(fields, str), "fields must be string"
    assert user_id > 0, "user_id must be positive integer"

    domain = "https://api.vk.com/method"
    access_token = config.VK_CONFIG['access_token']
    user_id = user_id

    query_params = {
        'domain': domain,
        'access_token': access_token,
        'user_id': user_id,
        'fields': fields
    }

    query = "{domain}/friends.get?access_token={access_token}&user_id={user_id}&fields=" \
            "{fields}&v=5.53".format(**query_params)
    response = get(query).json()
    try:
        response = response['response']['items']
    except:
        return []
    for num, friend in enumerate(response):
        user = User(id=friend['id'],
                    first_name=friend['first_name'],
                    last_name=friend['last_name'],
                    online=friend['online'])
        try:
            user.bdate = friend['bdate']
        except:
            pass
        response[num] = user
    return response
Esempio n. 3
0
def get_friends(user_id, fields):
    """ Returns a list of user IDs or detailed information about a user's friends """
    assert isinstance(user_id, int), "user_id must be positive integer"
    assert isinstance(fields, str), "fields must be string"
    assert user_id > 0, "user_id must be positive integer"

    domain = "https://api.vk.com/method"
    access_token = '949de9049e46bce7b329236f68f0f6f94d2fc0656ef260dde73273342572c4f62a837405b5b769f0c501d'
    user_id = user_id
    fields = fields
    v = '5.103'

    q_params = {
        'domain': domain,
        'access_token': access_token,
        'user_id': user_id,
        'fields': fields,
        'v': v
    }

    query = f"{domain}/friends.get?access_token={access_token}&user_id={user_id}&fields={fields}&v={v}".format(
        **q_params)
    response = get(query).json()

    try:
        response = response['response']['items']
    except:
        return []

    for num, friend in enumerate(response):
        user = User(id=friend['id'],
                    first_name=friend['first_name'],
                    last_name=friend['last_name'],
                    online=friend['online'])
        try:
            user.bdate = friend['bdate']
        except:
            pass
        response[num] = user
    return response