javascript - OAuth 同意屏幕 localhost

标签 javascript gmail gmail-api

我正在尝试使用 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

最佳答案

不确定这是否对其他人有帮助,但在通过 Google Cloud Console 标记为内部的应用上,在“URI”下添加 http://localhost 如下对我有用。

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

关于javascript - OAuth 同意屏幕 localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55129498/

相关文章:

javascript - 资源解释为脚本,但在注入(inject) angular-route.map 时以 MIME 类型 text/html 传输

Javascript html 从外部文件调用外部对象

python - 电子邮件脚本 - 回复邮件 Gmail 对话

css - Gmail 应用程序 (Android) 上的响应式电子邮件 - rem 和 heights

Javascript 和 Gmail 相当于 Applescript 和 Apple Mail

javascript - Gmail、nodemailer、OATH2 刷新 token 不起作用

javascript - 如何在 Javascript 中设置通过 Gmail Api 发送邮件的授权?

javascript - 在标记簇组中搜索标记 Leaflet-MarkerCluster

javascript - 通过 HTTP 请求向 gmail 帐户添加过滤器?

javascript - 单选按钮上的本地存储