educative.io

Educative

Not able to get access token

Hello Sir, i am not able to get access token…i got authorization code but not able to get access token …
please help me to get it

from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

SCOPES = ['https://www.googleapis.com/auth/blogger',
      'https://www.googleapis.com/auth/blogger.readonly']
      
def main():
   flow = InstalledAppFlow.from_client_secrets_file(
   'client_secret.json', SCOPES)  
   credentials = flow.run_console(
   authorization_prompt_message='Authorize the app using:\\n{url}', 
   authorization_code_message='Enter the authorization code: ')
   print (credentials)

   main()

Hi @dream_creativity, Thanks for reaching out to us.
Kindly follow the following steps and you will be able to get token access:
1. Open your Json File which is created and downloaded in the previous lesson.
2. Copy client_id, client_secret, and project_id from the downloaded JSON file.
3. Go to your lesson, click on Edit button and then paste client_id, client_secret, and project_id there like below:


4. Click Run button.
5. Copy the URL from here.

6. Paste it into a new browser tab, and you’ll be redirected to the Google sign-in page.

7. After you sign in to your Google account, you’ll be asked to authorize the app. Click the Allow button.

8. Copy the authorization code and paste it in the widget above where it asks for an input following the "Enter the authorization code:"

9. Press the Enter key, and you’ll get a JSON object as the output.

10. Copy the JSON object from the output of the above code and paste it into the widget below.

11. Now press the Save button.
12. Now you can successfully get token access.

That’s it, Hope it will help.
Happy Learning :blush: