Tell me, please, why these fields come back without any problems:

profiles = api.users.get(user_id=user_id, fields = "bdate, city, sex, country, nickname, followers_count, occupation") 

And the rest do not return?

Those. if i write:

 profiles = api.users.get(user_id=user_id, fields = "bdate, city, sex, country, nickname, followers_count, occupation, activities, home_town") 

he will not return the last two ...

In the documentation of VKontakte it is written that for some fields a token needed, but those fields for which it is needed return without problems. The other fields are very necessary ...)

  • Maybe it is that they simply do not have? - Pavel Durmanov
  • No, unfortunately they are, and in theory, even fields that are not filled in by the user should be returned, only empty ... - Cyril Morozov
  • Check the version of the VK API that you are using or, more precisely, that your library uses on python. It is possible that the problem lies in it .. - MrModest
  • thanks, the last one is worth ... - Kirill Morozov

1 answer 1

There are several options on api on python, in fact these are requests with urls and headers, so you simply check the URLs, see what comes in, maybe you missed something:

  def get_user(vk_id, access_token): url = "https://api.vk.com/method/users.get?user_ids={0}&fields=photo_400_orig&v=5.60".format(vk_id) headers = {'Content-type': 'application/json', 'Accept': 'text/plain', 'Content-Encoding': 'utf-8'} res = requests.get('https://api.vk.com/method/account.getProfileInfo?user_ids={0}&access_token={1}'. format(vk_id, access_token), headers=headers) print(res.json()) if 'error' not in res.json(): try: response = requests.get(url, headers=headers) photo = response.json()['response'][0]['photo_400_orig'] except Exception as e: print(e) photo = None user = res.json()['response'] name = user['first_name'] vk_id = 'vk_' + str(vk_id) sex = user['sex'] or 0 if 'home_town' in user: city = user['home_town'] elif 'city' in user: city = user['city']['title'] else: city = None birth = time.mktime(datetime.strptime(user['bdate'], '%d.%m.%Y').timetuple()) or 0 return {'name': name, 'sex': sex, 'birth': birth, 'city': city, 'photo': photo, 'id': vk_id} return False