Update app.py
Browse files
app.py
CHANGED
@@ -1039,46 +1039,7 @@ def users():
|
|
1039 |
return render_template('user.html')
|
1040 |
|
1041 |
|
1042 |
-
VK_CLIENT_ID = '52295022'
|
1043 |
-
VK_CLIENT_SECRET = 'your_client_secret'
|
1044 |
-
REDIRECT_URI = 'https://dmtuit-psy-vk.hf.space/pages'
|
1045 |
|
1046 |
-
# Маршрут для обмена кода на access_token
|
1047 |
-
@app.route('/exchange_code', methods=['POST'])
|
1048 |
-
def exchange_code():
|
1049 |
-
data = request.json
|
1050 |
-
code = data.get('code')
|
1051 |
-
device_id = data.get('deviceId')
|
1052 |
-
|
1053 |
-
if not code or not device_id:
|
1054 |
-
return jsonify({'error': 'Code and device_id are required'}), 400
|
1055 |
-
|
1056 |
-
# Обмен кода на access_token
|
1057 |
-
token_url = f'https://oauth.vk.com/access_token?client_id={VK_CLIENT_ID}&client_secret={VK_CLIENT_SECRET}&redirect_uri={REDIRECT_URI}&code={code}'
|
1058 |
-
token_response = requests.get(token_url)
|
1059 |
-
|
1060 |
-
if token_response.status_code != 200:
|
1061 |
-
return jsonify({'error': 'Failed to exchange code for access token'}), 500
|
1062 |
-
|
1063 |
-
token_data = token_response.json()
|
1064 |
-
access_token = token_data.get('access_token')
|
1065 |
-
|
1066 |
-
if not access_token:
|
1067 |
-
return jsonify({'error': 'No access token returned'}), 500
|
1068 |
-
|
1069 |
-
# Теперь получаем информацию о пользователе с помощью access_token
|
1070 |
-
user_info_url = f'https://api.vk.com/method/users.get?v=5.131&access_token={access_token}'
|
1071 |
-
user_info_response = requests.get(user_info_url)
|
1072 |
-
|
1073 |
-
if user_info_response.status_code != 200:
|
1074 |
-
return jsonify({'error': 'Failed to get user info from VK'}), 500
|
1075 |
-
|
1076 |
-
user_info_data = user_info_response.json()
|
1077 |
-
if 'response' in user_info_data and len(user_info_data['response']) > 0:
|
1078 |
-
user_info = user_info_data['response'][0]
|
1079 |
-
return jsonify(user_info)
|
1080 |
-
else:
|
1081 |
-
return jsonify({'error': 'User info not found'}), 500
|
1082 |
|
1083 |
|
1084 |
|
|
|
1039 |
return render_template('user.html')
|
1040 |
|
1041 |
|
|
|
|
|
|
|
1042 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1043 |
|
1044 |
|
1045 |
|