Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Oauth导致更多权限问题_Google Apps Script_Google Oauth_Google Contacts Api - Fatal编程技术网

Google apps script Oauth导致更多权限问题

Google apps script Oauth导致更多权限问题,google-apps-script,google-oauth,google-contacts-api,Google Apps Script,Google Oauth,Google Contacts Api,几个月来,我一直在努力解决这个问题,但情况越来越糟 我在GoogleApps脚本中有一个简单的程序,可以从一张工作表中获取电子邮件地址,并将其放入相应的GoogleContacts组中。直到大约一个月前它停止工作时,它一直运转良好 请帮助我: 1) 了解我是否真的需要使用API来完成我正在做的事情 2) 检查下面我的工作,看是否有遗漏的地方 原始问题: 当我运行这段代码时,我得到一个错误:“您没有执行该操作的权限。” 为了解决这些问题,我已经: -确保在我的云控制台中启用了联系人API。 -多次

几个月来,我一直在努力解决这个问题,但情况越来越糟

我在GoogleApps脚本中有一个简单的程序,可以从一张工作表中获取电子邮件地址,并将其放入相应的GoogleContacts组中。直到大约一个月前它停止工作时,它一直运转良好

请帮助我:

1) 了解我是否真的需要使用API来完成我正在做的事情

2) 检查下面我的工作,看是否有遗漏的地方

原始问题:

当我运行这段代码时,我得到一个错误:“您没有执行该操作的权限。”

为了解决这些问题,我已经: -确保在我的云控制台中启用了联系人API。 -多次禁用并重新启用它。 -使用该程序创建了一个新文件并启用了新联系人API。 -为新程序创建了凭据(此后一天有效)。 -联系谷歌云支持和G套件支持,以确保设置正确(他们不支持脚本或联系人)

问题2:

我曾尝试添加Oauth 2代码,但现在它给了我一个错误:“您没有调用getActiveSpreadsheet的权限。”

它们的问题在下面的Oauth 2代码中吗?(我删除了我的个人信息。)

  • 您是否登录了多个Google帐户?这通常会导致授权问题。尝试注销所有内容,然后只登录一个帐户

  • 这是在触发器上运行还是手动运行公式

  • 是否为电子表格的所有者并以所有者身份登录?您是否在电子表格的容器绑定脚本中运行此测试

  • 如果您是电子表格的所有者,并且您只是将电子表格中的电子邮件地址添加到您自己的Gmail帐户中,那么您没有理由需要使用API或OAuth协议

  • 正如另一位评论者提到的,您请求的范围是什么?要从电子表格中设置一个简单的脚本来添加联系人,您可能只需要列出两个。您可以通过选择查看-->显示清单文件来手动设置它们。例如:

    {
       "timeZone": "America/New_York",
       "dependencies": {
         },
       "oauthScopes": [
         "https://www.googleapis.com/auth/script.container.ui",
         "https://www.googleapis.com/auth/spreadsheets"
         ]  
    }
    

  • 检查你的应用程序脚本清单文件-你在那里设置了作用域吗?如果是这样,它们将覆盖任何自动范围检测,并按原样使用。如果清单文件中没有任何作用域,请选中文件->项目属性->作用域“oauthScopes”:[“”、“”、“”]以上是我现在在其中的内容。这很好,但不让我完成工作。非常感谢你在这方面的帮助!!!1) 我已经注销了所有内容,正在测试,只附带了一个帐户。2)还没有触发。只是尝试从菜单下拉菜单或脚本编辑器中运行。3) 我是主人。这是在我自己的域上运行的。脚本未与任何人共享。这是集装箱。4) 我是我域的所有者,使用我自己的域帐户工作。5) 如果我不需要API,那么我就不需要担心添加作用域。还有其他建议吗?我是否应该将GSuite帐户设置重置为默认设置?我将重新开始:通过转到并“删除访问权限”删除此应用程序中的权限。然后注释掉代码中的所有内容(最好是删除所有内容),但不包括测试函数,如上所述在清单文件中显式设置作用域,然后尝试从脚本编辑器运行该函数。然后会发生什么…?所以我删除了我所有应用程序的所有权限。还打开了一个新的sheets文件并粘贴到上面的测试函数中。得到了相同的精确错误。然后我在上面添加了电子表格和UI范围。错误特别是“您没有添加联系人的权限”。因此我添加了联系人范围。一切都重新授权了。但仍然得到同样的“你没有执行该操作的权限”。我甚至需要作用域吗?这看起来像是在你的评论上面,因为这是我的联系人和我的脚本在同一个电子邮件地址下,他们不应该。对于这个新的文件,我也进入并授权了联系人API
    function getContactsService() {
      // Create a new service with the given name. The name will be used when
      // persisting the authorized token, so ensure it is unique within the
      // scope of the property store.
      return OAuth2.createService('contacts')
    
          // Set the endpoint URLs, which are the same for all Google services.
          .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
          .setTokenUrl('https://accounts.google.com/o/oauth2/token')
    
          // Set the client ID and secret, from the Google Developers Console.
          .setClientId('blablabla.apps.googleusercontent.com')
          .setClientSecret('blablabla')
    
          // Set the name of the callback function in the script referenced
          // above that should be invoked to complete the OAuth flow.
          .setCallbackFunction('authCallback')
    
          // Set the property store where authorized tokens should be persisted.
          .setPropertyStore(PropertiesService.getUserProperties())
    
          // Set the scopes to request (space-separated for Google services).
          .setScope('https://www.google.com/m8/feeds')
          .setScope('https://www.googleapis.com/auth/spreadsheets')
    
          // Below are Google-specific OAuth2 parameters.
    
          // Sets the login hint, which will prevent the account chooser screen
          // from being shown to users logged in with multiple accounts.
          .setParam('login_hint', Session.getActiveUser().getEmail())
    
          // Requests offline access.
          .setParam('access_type', 'offline')
    
          // Forces the approval prompt every time. This is useful for testing,
          // but not desirable in a production application.
          .setParam('approval_prompt', 'force');
    }
    
    {
       "timeZone": "America/New_York",
       "dependencies": {
         },
       "oauthScopes": [
         "https://www.googleapis.com/auth/script.container.ui",
         "https://www.googleapis.com/auth/spreadsheets"
         ]  
    }