0

enter image description here In that screenshot this is the front end, after Google login I have got auth_code in the backend flask API, now how to read restricted Google sheet data based on that user auth_code

Thanks In advance

coder
  • 23
  • 6
  • Does this answer your question? [How do I access (read, write) Google Sheets spreadsheets with Python?](https://stackoverflow.com/questions/9690138/how-do-i-access-read-write-google-sheets-spreadsheets-with-python) – Daviid Aug 03 '23 at 10:18
  • @Daviid Thanks for your answer, But in Flask API I have got auth_code, sheet_url, and sheet_name from the front end so how to create credentials using google auth_code or google refresh token? – coder Aug 03 '23 at 14:35

1 Answers1

0

Here's a step-by-step guide on how to achieve this:

Set up a Google Cloud Platform (GCP) project:

Go to the Google Cloud Console (https://console.cloud.google.com/) and create a new project. Enable the Google Sheets API for your project. Create credentials (OAuth 2.0 client ID) for your application. Obtain the user's Auth code:

When the user wants to access their restricted data, direct them to a Google OAuth consent screen, where they'll log in and grant your application the necessary permissions. After granting permission, the user will be redirected to your application's redirect URL with the Auth code appended as a query parameter. Exchange the Auth code for an access token:

In your application, use the Auth code to request an access token by making a POST request to the Google OAuth token endpoint. The request should include your client ID, client secret, redirect URL, and the Auth code. Use the access token to read Google Sheet data:

Once you have obtained the access token, you can use it to authenticate your API requests to read the restricted Google Sheet data. Use the Google Sheets API to fetch the data from the Sheet. You'll need to specify the Sheet ID and the range of data you want to read.

  • can you provide me the code step by step? – coder Aug 07 '23 at 02:59
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 07 '23 at 17:07