Omkar008 commited on
Commit
864b722
1 Parent(s): b4bcc22

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +13 -12
test.py CHANGED
@@ -40,21 +40,22 @@ 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
  print(response.json())
54
- user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token}"})
55
  jobs_query = "subject:New application:ios"
56
  gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={jobs_query}&maxResults=110"
57
- gmail_response = requests.get(gmail_url, headers={"Authorization": f"Bearer {access_token}"})
58
  messages = gmail_response.json().get("messages", [])
59
  print(messages)
60
  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
+ user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token_new}"})
56
  jobs_query = "subject:New application:ios"
57
  gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={jobs_query}&maxResults=110"
58
+ gmail_response = requests.get(gmail_url, headers={"Authorization": f"Bearer {access_token_new}"})
59
  messages = gmail_response.json().get("messages", [])
60
  print(messages)
61
  print("Printing gmail response")