【问题标题】:OAuth consent screen localhostOAuth 同意屏幕 localhost
【发布时间】:2019-08-03 09:34:08
【问题描述】:

我正在尝试使用 Gmail API javascript 代码访问其他电子邮件,代码如下:-

function authenticate() {
        return gapi.auth2.getAuthInstance()
            .signIn({ scope: "https://mail.google.com/ https://www.googleapis.com/auth/gmail.compose https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.readonly" })
            .then(function () { console.log("Sign-in successful"); },
                function (err) { console.error("Error signing in", err); });
    }
    function loadClient() {
        return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/gmail/v1/rest")
            .then(function () { console.log("GAPI client loaded for API"); },
                function (err) { console.error("Error loading GAPI client for API", err); });
    }
    // Make sure the client is loaded and sign-in is complete before calling this method.
    function execute() {
        return gapi.client.gmail.users.getProfile({})
            .then(function (response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
            },
                function (err) { console.error("Execute error", err); });
    }
    gapi.load("client:auth2", function () {
        gapi.auth2.init({ client_id: "681860637449-ar2gfuhr23nf88h2ct7b5fs0oh213a0n.apps.googleusercontent.com" });
    });

当我尝试访问其他电子邮件时,我遇到了关于 此应用未验证的问题,这里是
的屏幕截图 1. 同意屏幕(已发布 URL)
2. Gmail 登录(从 javascript 代码登录)
3. 应用未验证

1. Consent Screen
2. Gmail Login
3. App not verified

【问题讨论】:

  • 您是否检查过 DaImTo 提供的关于如何验证应用程序的 Gmail API Google OAuth 的 SO post 解决方案?从 2017 年 7 月 18 日开始,请求某些敏感 OAuth 范围的 Google OAuth 客户端将接受 Google 的审核。这里还有一份关于Unverified Apps 的支持文档。
  • 但它仍然无济于事,因为同意屏幕不接受本地主机。我已经搜索了整个堆栈,但网络仍然找不到解决方案,因为没有准确的解决方案来测试本地主机 gmail api。
  • 那么@namco 你解决了这个问题吗?
  • @nullwriter 尚未解决 .. 发现您需要购买一些东西才能购买某种商务套件。

标签: javascript gmail gmail-api


【解决方案1】:

不确定这是否对其他人有帮助,但在“URI”下添加http://localhost 对我有用,通过谷歌云控制台标记为内部的应用程序。

  1. 如果您的应用不是“内部”应用,则您必须按照我阅读的内容执行手动验证步骤 - 对此一无所知,我的应用是内部应用
  2. 为了解决本地主机问题,将主机添加到凭据配置而不是 OAuth2 同意屏幕配置似乎对我有用,至少我在本地主机上的 Web 应用程序检索 Google 表格(配置不直观,因为两个 GCP 设置页面的域验证不同):

【讨论】:

    猜你喜欢
    • 2019-12-07
    • 2020-10-29
    • 2018-03-01
    • 2020-10-25
    • 1970-01-01
    • 2019-08-15
    • 2021-06-15
    • 2020-05-02
    • 2018-10-06
    相关资源
    最近更新 更多