Omkar008 commited on
Commit
8e36064
1 Parent(s): 59d6250

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +15 -15
test.py CHANGED
@@ -40,23 +40,23 @@ async def auth_google(code: str):
40
  #This code is basically the authorization code and this authorization code helps us to get the access token with the required scopes that we have set .
41
  #We require the gmail.readonly scopes that requires verification of our application and all.
42
  token_url = "https://accounts.google.com/o/oauth2/token"
43
- # print(code)
44
- # data = {
45
- # "code": code,
46
- # "client_id": GOOGLE_CLIENT_ID,
47
- # "client_secret": GOOGLE_CLIENT_SECRET,
48
- # "redirect_uri": GOOGLE_REDIRECT_URI,
49
- # "grant_type": "authorization_code",
50
- # }
51
- # response = requests.post(token_url, data=data)
52
- # access_token = response.json().get("access_token")
53
- access_token_new = code
54
- # print(response.json())
55
- print(access_token_new)
56
- user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token_new}"})
57
  jobs_query = "subject:New application:ios"
58
  gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={jobs_query}&maxResults=110"
59
- gmail_response = requests.get(gmail_url, headers={"Authorization": f"Bearer {access_token_new}"})
60
  messages = gmail_response.json().get("messages", [])
61
  print(messages)
62
  print("Printing gmail response")
 
40
  #This code is basically the authorization code and this authorization code helps us to get the access token with the required scopes that we have set .
41
  #We require the gmail.readonly scopes that requires verification of our application and all.
42
  token_url = "https://accounts.google.com/o/oauth2/token"
43
+ print(code)
44
+ data = {
45
+ "code": code,
46
+ "client_id": GOOGLE_CLIENT_ID,
47
+ "client_secret": GOOGLE_CLIENT_SECRET,
48
+ "redirect_uri": GOOGLE_REDIRECT_URI,
49
+ "grant_type": "authorization_code",
50
+ }
51
+ response = requests.post(token_url, data=data)
52
+ access_token = response.json().get("access_token")
53
+ # access_token_new = code
54
+ print(response.json())
55
+ # print(access_token_new)
56
+ user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token}"})
57
  jobs_query = "subject:New application:ios"
58
  gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={jobs_query}&maxResults=110"
59
+ gmail_response = requests.get(gmail_url, headers={"Authorization": f"Bearer {access_token}"})
60
  messages = gmail_response.json().get("messages", [])
61
  print(messages)
62
  print("Printing gmail response")