Use google API with no sign in auth2

36 Views Asked by At

The only way I could make auth2 work is using this code:

 google.accounts.id.initialize({
            client_id: CLIENT_ID,
            callback: loadAPI,
            ux_mode: "redirect",
            prompt_parent_id: "signinBox",
            context: "signin",
            cancel_on_tap_outside: false,
            auto_select: true
          });
          google.accounts.id.prompt((notification) => {
            if(notification.isNotDisplayed() || notification.isSkippedMoment()) {
              console.log("Prompt cancelled by user");
            }
          });

I want to use a public sheet and do not want to force anyone to sign in with Google if possible. The examples for this on the net are not for the new auth2. Is there a way to do this with auth2 so that I do not have to login?

Edit: I found another way to do this but still requires a log in call for the token:

client = google.accounts.oauth2.initTokenClient({
              client_id: CLIENT_ID,
              scope: 'https://www.googleapis.com/auth/spreadsheets.readonly',
              callback: loadAPI

              });
              
              client.requestAccessToken();
0

There are 0 best solutions below