【问题标题】:You do not have permission to call getContacts您无权调用 getContacts
【发布时间】:2018-04-22 11:39:33
【问题描述】:

我正在开发将所有用户的联系人提取到卡片的 GMail 插件:

var contacts = ContactsApp.getContacts();

我已经在 Google API 控制台中启用了 ContactsAPI 并添加了范围: https://www.googleapis.com/auth/contacts.readonly

但错误仍然存​​在,并且项目的高级 Google 服务弹出窗口中缺少联系人 API。

【问题讨论】:

    标签: google-apps-script gmail-api google-contacts-api


    【解决方案1】:

    通过反复试验,this hard-to-find list 我设法让ContactsApp.getContacts() 工作。您需要添加此范围:

    "oauthScopes": [
      "https://www.google.com/m8/feeds",
    

    【讨论】:

      【解决方案2】:

      使用 ContactsApp 时无需启用 Contacts API 和设置范围。使用此功能时,在查看要使用的权限后,您的应用会自动选择必要的权限,以便 ContactsApp 正常工作。

      我使用的代码和你的一样:

      function myFunction() {
        // The code below will retrieve all the user's contacts
       var contacts = ContactsApp.getContacts();
      
        Logger.log(contacts)
      }
      

      这是我收到的结果:

      请检查并检查您的代码,您可能遗漏了什么。

      希望这会有所帮助。

      【讨论】:

      • 因此,启用了其他功能。可能是您的附加组件已验证?您的应用中启用了哪些范围?
      • 很遗憾,Gmail 插件并非如此。似乎没有自动发现机制(还没有?)。有谁知道所需的实际范围?
      • 实际上我遇到了这个问题,因为我在进行 Gmail 插件开发时覆盖了我的应用清单并在那里定义了 OAuth 范围。在这种情况下,Google 没有提示我,因为它无法自动检测所需的范围。解决方案是手动添加 OAuth 范围,如 @wulftone 的答案
      猜你喜欢
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      相关资源
      最近更新 更多