我正在尝试使用 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
如下对我有用。
关于javascript - OAuth 同意屏幕 localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55129498/