Gsuite configuration error for google drive

Hello,

I have configured Gsuite integration following the tutorial here : Google GSuite

After login in https://console.cloud.google.com
I create a new project and enabled Drive API

After this I have created a user credential
image

I setup Gsuite settings in erpnext with client id and client secret and it’s good. I can choose a google user to enable access

But when I try to run test script I have this issue

And when i try to request access

In browser console I get

Error in Template: microtemplate.js:62:11
var _p=[],print=function(){_p.push.apply(_p,arguments)};with(obj){
_p.push('<pre>// ERPNEXT GSuite integration //  function doGet(e){   return ContentService.createTextOutput('ok'); }  function doPost(e) {   var p = JSON.parse(e.postData.contents);    switch(p.exec){     case 'new':       var url = createDoc(p);       result = { 'url': url };       break;     case 'test':       result = { 'test':'ping' , 'version':'1.0'}   }   return ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON); }  function replaceVars(body,p){   for (key in p) {     if (p.hasOwnProperty(key)) {       if (p[key] != null) {         body.replaceText(\'','+key+','\', p[key]);       }     }   }     }  function createDoc(p) {   if(p.destination){     var folder = DriveApp.getFolderById(p.destination);   } else {     var folder = DriveApp.getRootFolder();   }   var template = DriveApp.getFileById( p.template )   var newfile = template.makeCopy( p.filename , folder );    switch(newfile.getMimeType()){     case MimeType.GOOGLE_DOCS:       var body = DocumentApp.openById(newfile.getId()).getBody();       replaceVars(body,p.vars);       break;     case MimeType.GOOGLE_SHEETS:       //TBD     case MimeType.GOOGLE_SLIDES:       //TBD   }   return newfile.getUrl() }  </pre>');}return _p.join(''); microtemplate.js:63:11
Error in Line 4, Col 109: microtemplate.js:65:12
undefined
Traceback (most recent call last):
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/integrations/doctype/gsuite_settings/gsuite_settings.py", line 75, in run_gsuite_script
    r = r.json()
  File "/home/auroraone1/ao-heliway/env/lib/python3.5/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/app.py", line 61, in application
    response = frappe.handler.handle()
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/__init__.py", line 1032, in call
    return fn(*args, **newargs)
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/integrations/doctype/gsuite_settings/gsuite_settings.py", line 86, in run_script_test
    r = run_gsuite_script('test')
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/integrations/doctype/gsuite_settings/gsuite_settings.py", line 78, in run_gsuite_script
    frappe.throw(r.text)
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/__init__.py", line 356, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/__init__.py", line 342, in msgprint
    _raise_exception()
  File "/home/auroraone1/ao-heliway/apps/frappe/frappe/__init__.py", line 315, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: <!DOCTYPE html><html lang="en"><head><meta name="description" content="Web word processing, presentations and spreadsheets"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"><link rel="shortcut icon" href="//ssl.gstatic.com/docs/common/drive_favicon1.ico"><title>Google Drive - Access Denied</title><link href="//fonts.googleapis.com/css?family=Product+Sans" rel="stylesheet" type="text/css"><style>/* Copyright 2019 Google Inc. All Rights Reserved. */
.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog-inline-block{display:inline}#drive-logo{margin:18px 0;position:absolute;white-space:nowrap}.docs-drivelogo-img{background-image:url('//ssl.gstatic.com/images/branding/googlelogo/1x/googlelogo_color_116x41dp.png');background-size:116px 41px;display:inline-block;height:41px;vertical-align:bottom;width:116px}.docs-drivelogo-text{color:#000;display:inline-block;opacity:0.54;text-decoration:none;font-family:'Product Sans',Arial,Helvetica,sans-serif;font-size:32px;text-rendering:optimizeLegibility;position:relative;top:-6px;left:-7px;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}@media (-webkit-min-device-pixel-ratio:1.5),(min-resolution:144dpi){.docs-drivelogo-img{background-image:url('//ssl.gstatic.com/images/branding/googlelogo/2x/googlelogo_color_116x41dp.png')}}</style><style>/* Copyright 2019 Google Inc. All Rights Reserved. */
.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog-inline-block{display:inline}.jfk-button{-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px;cursor:default;font-size:11px;font-weight:bold;text-align:center;white-space:nowrap;margin-right:16px;height:27px;line-height:27px;min-width:54px;outline:0px;padding:0 8px}.jfk-button-hover{-webkit-box-shadow:0 1px 1px rgba(0,0,0,.1);-moz-box-shadow:0 1px 1px rgba(0,0,0,.1);box-shadow:0 1px 1px rgba(0,0,0,.1)}.jfk-button-selected{-webkit-box-shadow:inset 0px 1px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0px 1px 2px rgba(0,0,0,0.1);box-shadow:inset 0px 1px 2px rgba(0,0,0,0.1)}.jfk-button .jfk-button-img{margin-top:-3px;vertical-align:middle}.jfk-button-label{margin-left:5px}.jfk-button-narrow{min-width:34px;padding:0}.jfk-button-collapse-left,.jfk-button-collapse-right{z-index:1}.jfk-button-collapse-left.jfk-button-disabled{z-index:0}.jfk-button-checked.jfk-button-collapse-left,.jfk-button-checked.jfk-button-collapse-right{z-index:2}.jfk-button-collapse-left:focus,.jfk-button-collapse-right:focus,.jfk-button-hover.jfk-button-collapse-left,.jfk-button-hover.jfk-button-collapse-right{z-index:3}.jfk-button-collapse-left{margin-left:-1px;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;border-bottom-left-radius:0;border-top-left-radius:0}.jfk-button-collapse-right{margin-right:0px;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;border-top-right-radius:0;border-bottom-right-radius:0}.jfk-button.jfk-button-disabled:active{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.jfk-button-action{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;background-color:#4d90fe;background-image:-webkit-linear-gradient(top,#4d90fe,#4787ed);background-image:-moz-linear-gradient(top,#4d90fe,#4787ed);background-image:-ms-linear-gradient(top,#4d90fe,#4787ed);background-image:-o-linear-gradient(top,#4d90fe,#4787ed);background-image:linear-gradient(top,#4d90fe,#4787ed);border:1px solid #3079ed;color:#fff}.jfk-button-action.jfk-button-hover{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;background-color:#357ae8;background-image:-webkit-linear-gradient(top,#4d90fe,#357ae8);background-image:-moz-linear-gradient(top,#4d90fe,#357ae8);background-image:-ms-linear-gradient(top,#4d90fe,#357ae8);background-image:-o-linear-gradient(top,#4d90fe,#357ae8);background-image:linear-gradient(top,#4d90fe,#357ae8);border:1px solid #2f5bb7;border-bottom-color:#2f5bb7}.jfk-button-action:focus{-webkit-box-shadow:inset 0 0 0 1px #fff;-moz-box-shadow:inset 0 0 0 1px #fff;box-shadow:inset 0 0 0 1px #fff;border:1px solid #fff;border:rgba(0,0,0,0) solid 1px;outline:1px solid #4d90fe;outline:rgba(0,0,0,0) 0}.jfk-button-action.jfk-button-clear-outline{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;outline:none}.jfk-button-action:active{-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.3);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.3);box-shadow:inset 0 1px 2px rgba(0,0,0,0.3);background:#357ae8;border:1px solid #2f5bb7;border-top:1px solid #2f5bb7}.jfk-button-action.jfk-button-disabled{background:#4d90fe;filter:alpha(opacity=50);opacity:0.5}.jfk-button-standard{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;background-color:#f5f5f5;background-image:-webkit-linear-gradient(top,#f5f5f5,#f1f1f1);background-image:-moz-linear-gradient(top,#f5f5f5,#f1f1f1);background-image:-ms-linear-gradient(top,#f5f5f5,#f1f1f1);background-image:-o-linear-gradient(top,#f5f5f5,#f1f1f1);background-image:linear-gradient(top,#f5f5f5,#f1f1f1);color:#444;border:1px solid #dcdcdc;border:1px solid rgba(0,0,0,0.1)}.jfk-button-standard.jfk-button-hover,.jfk-button-standard.jfk-button-clear-outline.jfk-button-hover{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;background-color:#f8f8f8;background-image:-webkit-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:-moz-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:-ms-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:-o-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:linear-gradient(top,#f8f8f8,#f1f1f1);border:1px solid #c6c6c6;color:#333}.jfk-button-standard:active,.jfk-button-standard.jfk-button-hover:active{-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);box-shadow:inset 0 1px 2px rgba(0,0,0,.1);background:#f8f8f8;color:#333}.jfk-button-standard.jfk-button-selected,.jfk-button-standard.jfk-button-clear-outline.jfk-button-selected{background-color:#eee;background-image:-webkit-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:-moz-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:-ms-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:-o-linear-gradient(top,#f8f8f8,#f1f1f1);background-image:linear-gradient(top,#f8f8f8,#f1f1f1);border:1px solid #ccc;color:#333}.jfk-button-standard.jfk-button-checked,.jfk-button-standard.jfk-button-clear-outline.jfk-button-checked{-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);box-shadow:inset 0 1px 2px rgba(0,0,0,.1);background-color:#eee;background-image:-webkit-linear-gradient(top,#eee,#e0e0e0);background-image:-moz-linear-gradient(top,#eee,#e0e0e0);background-image:-ms-linear-gradient(top,#eee,#e0e0e0);background-image:-o-linear-gradient(top,#eee,#e0e0e0);background-image:linear-gradient(top,#eee,#e0e0e0);border:1px solid #ccc;color:#333}.jfk-button-standard:focus{border:1px solid #4d90fe;outline:none}.jfk-button-standard.jfk-button-clear-outline{border:1px solid #dcdcdc;border:1px solid rgba(0,0,0,0.1);outline:none}.jfk-button-standard.jfk-button-disabled{background:#fff;border:1px solid #f3f3f3;border:1px solid rgba(0,0,0,0.05);color:#b8b8b8}.jfk-button-standard .jfk-button-img{opacity:.55}.jfk-button-standard.jfk-button-checked .jfk-button-img,.jfk-button-standard.jfk-button-selected .jfk-button-img,.jfk-button-standard.jfk-button-hover .jfk-button-img{opacity:0.9}.jfk-button-standard.jfk-button-disabled .jfk-button-img{filter:alpha(opacity=33);opacity:0.333}button.jfk-button{font-family:arial,sans-serif;height:auto}.jfk-button:hover{-webkit-box-shadow:0 1px 1px rgba(0,0,0,.1);-moz-box-shadow:0 1px 1px rgba(0,0,0,.1);box-shadow:0 1px 1px rgba(0,0,0,.1)}.jfk-button-action:hover{background-color:#357ae8;background-image:-webkit-linear-gradient(top,#4d90fe,#357ae8);background-image:-moz-linear-gradient(top,#4d90fe,#357ae8);background-image:-ms-linear-gradient(top,#4d90fe,#357ae8);background-image:-o-linear-gradient(top,#4d90fe,#357ae8);background-image:linear-gradient(top,#4d90fe,#357ae8);border:1px solid #2f5bb7}</style><style type="text/css">body {background-color: #fff; font-family: Arial,sans-serif; font-size: 13px; margin: 0; padding: 0;}a, a:link, a:visited {color: #112ABB;}</style><style type="text/css">.errorMessage {font-size: 12pt; font-weight: bold; line-height: 150%;}</style></head><body><div id="outerContainer"><div id="innerContainer"><div style="position: absolute; top: -80px;"><div id="drive-logo"><a href="/"><span class="docs-drivelogo-img" title="Google logo"></span><span class="docs-drivelogo-text">&nbsp;Drive</span></a></div></div><script type="text/javascript">
    function sendXhr(url, data, callback, retry) {
      var req;
      var startString = '&&&START&&&';
      var objIds = [
        'MSXML2.XMLHTTP.5.0',
        'MSXML2.XMLHTTP.4.0',
        'MSXML2.XMLHTTP.3.0',
        'MSXML2.XMLHTTP',
        'MICROSOFT.XMLHTTP.1.0',
        'MICROSOFT.XMLHTTP.1',
        'MICROSOFT.XMLHTTP'
      ];
      if (typeof XMLHttpRequest == 'undefined') {
        while (objIds[0]) {
          try {
            req = new ActiveXObject(objIds.pop());
            break;
          }
          catch(e) {}
        }
      }
      req = req || new XMLHttpRequest();
      req.onreadystatechange = function() {
        if (req.readyState == 4) {
          // Work around IE memory leak.
          req.onreadystatechange = nullFn;

          var token = req.getResponseHeader('X-Explorer-Token');
          if (retry && (req.status == 403 || req.status == 400) && token) {
            // Retry once with token.
            data = data + '&token=' + encodeURIComponent(token);
            sendXhr(url, data, callback, false);
          } else {
            var json = req.responseText;
            if (json.indexOf(startString) == 0) {
                json = json.substring(startString.length);
            }
            if (json.indexOf('{') == 0) {
              var jsonObj = eval('(' + json + ')');
              // Anything greater than 0 is an error in this case.
              callback('status' in jsonObj ? jsonObj['status'] : 1);
            } else {
              // Adhara's requestaccess endpoint only returns an empty 204 on
              // success (b/36214493).
              callback(req.status == 204 ? 0 : 1);
            }
          }
        }
      };
      req.open('POST', url, true);
      req.setRequestHeader('Content-Type',
          'application/x-www-form-urlencoded;charset=utf-8');
      req.setRequestHeader('X-Same-Domain', 'explorer');
      req.send(data);
    }
    function nullFn() {}
  function goToAccountsUrl() {var currentUrl = window.location.href;window.location = '\/\/docs.google.com\/accounts?continueUrl=' + escape(currentUrl);return false;}function requestAccess() {var confMsg = 'Request access to this Google Drive item?'; if (self !== top && !window.confirm(confMsg)) {return;}sendXhr( '\/sharing\/commonshare?authuser=', 'requestType=requestAccess&' + 'itemIds=1HyQ509RDwV4Z1Ysdrhi39rRJXjcsWdhFEz7rja_FgxohEybi7i4eeNTq&' + 'foreignService=explorer&' + 'shareService=explorer&' + 'authuser=' + '', function(status) {document.getElementById('message').style.display = 'none'; document.getElementById('buttons').style.display = 'none'; document.getElementById(status == 0 ? 'sendSuccess' : 'sendError').style.display = '';}, true);}</script><div style="clear:both"></div><div id="main"><div id="accessDeniedIcon"></div><p id="accessDeniedHeader">You need permission</p><div id="message"><p>Want in? Ask for access, or switch to an account with permission. <a href="https://support.google.com/drive?p=requesting_access&amp;hl=en" style="color: 15x; text-decoration: none;">Learn more</a></p><p>You are signed in as <b>jodeq@auroraone.space</b>.</p></div><p id="buttons" style="padding-top: 10px"><button id="requestButton" style="font-weight:bold" class="jfk-button jfk-button-action">Request access<script type="text/javascript">document.getElementById('requestButton').addEventListener('click', requestAccess);</script></button><button id="goToAccountsUrlButton" class="jfk-button jfk-button-standard">Switch accounts</button><script type="text/javascript">document.getElementById('goToAccountsUrlButton') .addEventListener('click', goToAccountsUrl);</script></p><div id="sendSuccess" style="display:none; font: 15px/1.6 Arial, sans-serif; color: #222; width: 480px"><p>Your request for access has been sent.</p><p>You will receive an email if and when your request is approved.</p><p style="padding-top: 10px; padding-bottom: 125px">Find out more <a href="https://support.google.com/drive?p=access_requested&amp;hl=en">about this topic at the Google Help Center</a></p></div><div id="sendError" style="display:none; font: 15px/1.6 Arial, sans-serif; color: #222; width: 480px"><p>We're sorry, but we were unable to send the message.</p><p>Please contact the person directly.</p><p style="padding-top: 10px; padding-bottom: 125px">Find out more <a href="https://support.google.com/drive?p=access_requested&amp;hl=en">about this topic at the Google Help Center</a></p></div></div><style>#accessDeniedHeader {color: #222; font: 32px Arial, sans-serif;}#accessDeniedIcon {background-image: url('//ssl.gstatic.com/docs/documents/share/images/locked_doc-2.svg'); float:  right ; height: 158px; width: 128px;}#main {position: relative; width: 640px; top: 30px;}#message {color: #222; font: 15px/1.6 Arial, sans-serif; width: 480px;}@media (max-width: 500px) {#accessDeniedHeader {color: #222; font: 25px Arial, sans-serif;}#accessDeniedIcon {background-image: url('//ssl.gstatic.com/docs/documents/share/images/locked_doc-1.svg'); height: 108px; width: 88px;}#main {width: 100%;}#message {width: 75%;}#outerContainer #innerContainer {margin-left: 20px; margin-right: 20px;}}</style></div></div></body><style>#outerContainer {margin: auto; max-width: 750px;}#innerContainer {margin-bottom: 20px; margin-left: 40px; margin-right: 40px; margin-top: 180px; position: relative;}</style></html>
desk.min.js:1:53327

​What am i missing here ?

I have setup gcalendar correctly and it works so it’s only drive API issue.

It could be the sharing/commonshare?authuser= there are no authuser

Alright, I figured out what I have missed.
I didn’t configured my script and try to use the standard one without access granted.

So don’t forget to setup the 1.1 Publish Google apps script from the documentation

hint : to recreate refresh_token you can go to https://myaccount.google.com/u/0/permissions?pli=1 and remove your OAuth.

1 Like