Shihab Rashid
Shihab Rashid

Reputation: 11

How to get the google sheets api credentials (client secrets, client id etc) and authorize through browser programmatically?

I am trying to authorize Sheets API v4 (including getting the credentials) through my webpage (let's suppose I have a button called "authorize google sheets"), so when anyone clicks that button they will be taken through the browser to authorize their google account (including creating credentials automatically), so that they do not have to go to console.developers.google.com/apis manually and create credentials.

Is there a way to do it or is there any way to not use credentials at all and authorize to sheets api?

Upvotes: 1

Views: 660

Answers (1)

Jacques-Guzel Heron
Jacques-Guzel Heron

Reputation: 2598

I understand that you want to request some Sheets API operation to your webpage users. If that is the case, there is no need to access the users credentials. The users only need to login and approve your scopes for Google Servers to send you an authorization code to run the request. You can see a execution summary here:

OAuth 2.0 for Web Server Applications

First of all you would need to include the relevant OAuth 2.0 scopes in your server. Then you can ask users to login and consent your scopes. Here are the steps needed for asking for users approval, you could follow its examples as a guideline. Finally, you could use the generated tokens to call Sheets API. Please ask me any question if you have any doubt.

Upvotes: 0

Related Questions