DmitrMakeev commited on
Commit
8f181ec
1 Parent(s): b65dee5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -1,24 +1,32 @@
1
- from flask import Flask, request, redirect, session, url_for
2
  import requests
3
  import os
 
4
 
5
  app = Flask(__name__)
6
- app.secret_key = os.getenv('SECRET_KEY') # Замените на ваш секретный ключ
 
7
 
8
  def get_access_token(code):
9
- client_id = os.getenv('APP_ID')
10
- client_secret = os.getenv('APP_SECRET')
11
- redirect_uri = os.getenv('red_uri')
12
-
13
- url = f'https://oauth.vk.com/access_token?client_id={client_id}&client_secret={client_secret}&redirect_uri={redirect_uri}&code={code}'
14
- response = requests.get(url)
15
- data = response.json()
16
-
17
- if 'access_token' in data:
18
- access_token = data['access_token']
19
- user_id = data['user_id']
20
- return access_token, user_id
21
- else:
 
 
 
 
 
 
22
  return None, None
23
 
24
  @app.route('/login')
 
1
+ from flask import Flask, request, redirect, session, url_for, abort
2
  import requests
3
  import os
4
+ import logging
5
 
6
  app = Flask(__name__)
7
+ app.secret_key = os.getenv('SECRET_KEY')
8
+ logging.basicConfig(level=logging.INFO)
9
 
10
  def get_access_token(code):
11
+ try:
12
+ client_id = os.getenv('APP_ID')
13
+ client_secret = os.getenv('APP_SECRET')
14
+ redirect_uri = os.getenv('red_uri')
15
+
16
+ url = f'https://oauth.vk.com/access_token?client_id={client_id}&client_secret={client_secret}&redirect_uri={redirect_uri}&code={code}'
17
+ response = requests.get(url)
18
+ response.raise_for_status()
19
+ data = response.json()
20
+
21
+ if 'access_token' in data:
22
+ access_token = data['access_token']
23
+ user_id = data['user_id']
24
+ return access_token, user_id
25
+ else:
26
+ logging.error("Ошибка при получении access_token: %s", data)
27
+ return None, None
28
+ except requests.RequestException as e:
29
+ logging.error("Ошибка при запросе access_token: %s", e)
30
  return None, None
31
 
32
  @app.route('/login')