Get gmail address using Google Apps Script, Error: redirect_uri_mismatch

I try get gmail address of user use my app script. I have consulted several places :

and in the question I posted before but can't do it and there's a new problem.

This code file gs:

function doGet(e) {

 var tmp = HtmlService.createTemplateFromFile("testapi");
 return tmp.evaluate(); 


This code file html:

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="google-signin-client_id" content="">
    <title>Oauth2 web</title>

    <!-- Google library -->
    <script src="" async defer></script>

    <!-- Jquery library to print the information easier -->
    <script src=""></script>

    <!-- Bootstrap library for the button style-->
    <link rel="stylesheet" href="" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div id="profileinfo">
<div class="g-signin2" data-onsuccess="onSignIn"></div>

            function onSignIn(googleUser) {
              var profile = googleUser.getBasicProfile();
              console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
              console.log('Name: ' + profile.getName());
              console.log('Image URL: ' + profile.getImageUrl());
              console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.

              $("#profileinfo").append("<h2>Sup " + profile.getName() + ", welcome home my friend</h2>");
              $("#profileinfo").append("<img style='width:250px;height:250px' src='" + profile.getImageUrl() + "'><br><br>");
              $("#profileinfo").append("<p>Your email is: " + profile.getEmail() + "</p>");


<button type="button" class="btn btn-danger" onclick="signOut();">Sign out</button>

            function signOut() {
               var auth2 = gapi.auth2.getAuthInstance();
               auth2.signOut().then(function () {
                 console.log('User signed out.');
               $("#profileinfo").append("<h2>Goodbye old friend</h2>");

create clientID

URL of Apps script




I reproduced your steps, and it does retrieve the html but when you try to sign in, the following error is thrown in a pop-up window:

“Error: redirect_uri_mismatch

The JavaScript origin in the request,, does not match the ones authorized for the OAuth client.”

You need to copy the URL from the error message and follow these steps:

1) Select the project in google cloud and go to credentials -> Oauth consent screen , in authorized domains add “”.

2) Edit your credentials and add the URL you got before to the “Authorized JavaScript origins” part.

3) Deploy as a web app in a new version.

If I understood right, that should work, although a couple of things to point out on how you deploy the web app:

1) If you set the deploy options to execute the app as the user accessing the app, when you access with the link, App script will prompt its own consent screen to log in, then when you click on the sign-in option it’ll automatically sign-in with the user that’s already logged.

2) If you set the deploy options to execute the app as you and in the access option you select “Anyone, even anonymous”, when you click on the sign-in option it’ll prompt you the expected oauth consent screen to log in. The only thing is that when you sign-out and click on sign-in button again, it’ll automatically log in with the previous credentials (In a normal server it would prompt you the consent screen again).

Without the need of implementing Oauth, you can set the deployment options as the setup in “1)”, and then use the User object from App Script to obtain the user’s email, although that’s the only information you can get from there [1].



If I well understand you want to get in frontend the email and user profile information you don't need to do all this complex things.

In backend create this function :

function getUser(){
  //Session.getEffectiveUser().getEmail(); // Just for scope
  var url = "";
  var param = {
    method      : "Get",
    headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
    'muteHttpExceptions' :true
  var html = UrlFetchApp.fetch(url,param);
  var data = JSON.parse(html.getContentText());
  /* Result is JSON
  {"id":"Google User ID","email":"[email protected]","verified_email":true,"picture":"https://xxxxxxxxxxxxxxxxx/photo.jpg"}
  return data

Then now in frontend you can call this function to get in the user details :

function getUserDetails(){
        .withSuccessHandler(function(user) {
            //Do some stuffs with user details
            // Email is in
        .withFailureHandler(function(msg) {

As the script request the Session.getEffectiveUser().getEmail() the user grant scope to allow to get user information.

Then you just have to query the endpoint to get user details.



Web Apps created inside Google Apps Script are always served inside an IFRAME and cannot be accessed outside the IFRAME.

Therefore the standard Google sign-in component cannot be embedded into these apps.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.