让我的服务帐户在同一个 web 应用程序上进行身份验证是一件非常令人头疼的事情,我也让用户通过 oauth2 登录。
所以我想知道,这可能吗?
如果不是,是否应该坚持使用服务帐户?是否必须自行对用户进行身份验证(老派风格)?哈哈
谢谢。
关于服务帐户,我已经启用了域范围委托,在我的 G Suite 管理控制台中启用了客户端密钥 + api 范围,并且已经获得了 php 示例,并且书籍 api 正常工作。然而,每当我尝试除书籍之外的任何其他 api 时,我都会收到错误,
客户端无权使用此方法检索访问令牌
更新:我尝试使用@dalmto的示例,并添加了几行来测试gmail api,例如:
putenv('GOOGLE_APPLICATION_CREDENTIALS=credentials.json');
$user = 'email@domain.de';
function getGoogleClient() {
return getServiceAccountClient();
}
function getServiceAccountClient() {
try {
// Create and configure a new client object.
$client2 = new Google_Client();
$client2->useApplicationDefaultCredentials();
$client2->setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/admin.directory.user.readonly','https://www.googleapis.com/auth/userinfo.profile','https://www.googleapis.com/auth/gmail.readonly','https://www.googleapis.com/auth/calendar'));
$client2->setAccessType('offline');
$client2->setSubject($user);
return $client2;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
$newGoogleClient = getGoogleClient();
$service3 = new …Run Code Online (Sandbox Code Playgroud) php google-oauth service-accounts gmail-api google-workspace
我无法找到我的 Gmail 帐户的 userId 来使用 Gmail API。所以有人可以找到。你能告诉我吗?
我正在研究 Gmail API。假设我有兴趣查看哪封邮件包含字符串“foobar2000”。
到目前为止,这是我的代码:
主程序.java
package manhattan.email.bot;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.services.gmail.model.Message;
import com.google.api.services.gmail.model.MessagePart;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.Properties;
import manhattan.email.bot.google.GmailCredentials;
import manhattan.email.bot.google.GmailService;
import manhattan.email.bot.google.GmailServiceImpl;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
public class Main {
static final String MY_EMAIL = "xxxxx@gmail.com";
static final String MY_CLIENT_ID = "xxxxxapps.googleusercontent.com";
static final String MY_CLIENT_SECRET = "xxxxx";
static final String MY_ACCESS_TOKEN = "xxxxx";
static final String MY_REFRESH_TOKEN = "xxxxx";
public static void main(String[] args) {
try {
GmailService gmailService = …Run Code Online (Sandbox Code Playgroud) 正如标题所述,是否有人成功为通过gmail api发送的电子邮件启用了 3 种安全机制?
目前,我通过 gmail-api (http) 发送的所有电子邮件均已被收件人成功接收,但没有任何安全标记。这适用于我们的 chrome 扩展和 gmail-addon。
我试图通过使用以下 API 搜索其消息 ID 来获取特定电子邮件: https: //developers.google.com/gmail/api/guides/filtering
例如message_id = "<C6P4M-GEE8PzO8qf0=oTQ3ZJeFB_uASDAAF9AJSRRiNuUVBzan0w@mail.gmail.com>"
我可以通过修改以下内容来实现它:
MESSAGE = GMAIL.users().messages().list(userId='me',labelIds='INBOX').execute()
但如何修改它以仅搜索具有 message_id 的特定电子邮件?
目前,我尝试使用一种极其低效的解决方案,该解决方案的工作原理是使用 messages.list 扫描整个收件箱,然后找到匹配的电子邮件消息 ID。
我正在尝试使用 Gmail API 发送电子邮件。但我收到这个错误
googleapi:错误 403:请求的身份验证范围不足。更多详细信息:原因:权限不足,消息:权限不足
我认为这可能与配置有关,我还遵循了 google 的 Go 快速入门,这里是 getClient 函数:
func getClient(config *oauth2.Config) *http.Client {
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
tokFile := "token.json"
tok, err := tokenFromFile(tokFile)
if err != nil {
tok = getTokenFromWeb(config)
saveToken(tokFile, tok)
}
return config.Client(context.Background(), tok)
}
Run Code Online (Sandbox Code Playgroud)
这是发送的代码:
case "pass":
templateData := struct {
VerPass string
}{
VerPass: cont1,
}
emailBody, …Run Code Online (Sandbox Code Playgroud) 我们通过 Gmail API 应用程序发送的所有电子邮件都存在问题。所有邮件都附带有关电子邮件安全的警告
这条消息看起来很危险。许多人将类似的邮件标记为网络钓鱼诈骗,因此这可能包含不安全的内容。避免点击链接、下载附件或回复个人信息。

仅当通过我们发送电子邮件时才会发生这种情况Gmail API,但通过发送电子邮件时SMTP将在没有任何警告的情况下传递消息。
此警告消息会出现在通过我们的 Gmail API 应用程序发送的所有电子邮件上,无论发件人是 Google Workspace 用户还是免费 Gmail 用户。
有人可以帮忙吗?
google-api-client我一直在开发一个小项目,该项目连接到用户的 Gmail 收件箱并使用2.0.0 和google-api-services-gmail版本 v1-rev20220404-2.0.0读取邮件
当我尝试构建 Gmail 服务时
service = new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY,
authorize).setApplicationName(Main.APPLICATION_NAME).build();
Run Code Online (Sandbox Code Playgroud)
它抛出一个 IllegalStateException 说
“您当前运行的是 2.0.0 版的 google-api-client。您至少需要 1.15 版的 google-api-client 才能运行 1.25.0 版的 Gmail API 库。”
起初我以为可能是我安装的模块不是最新的或者什么的,但这并没有真正意义,所以我尝试调试并进入了 Gmail.java 类。
该代码以非常简单的方式检查版本,如果条件为 false,则抛出异常
static {
Preconditions.checkState(GoogleUtils.MAJOR_VERSION == 1 && GoogleUtils.MINOR_VERSION >= 15,
"You are currently running with version %s of google-api-client. You need at least version 1.15 of google-api-client to run version 1.25.0 of the Gmail API library.",
new Object[]{GoogleUtils.VERSION});
}
Run Code Online (Sandbox Code Playgroud)
我认为这就是问题所在,我的 MAJOR_VERSION 为 2 …
我希望与 Gmail API 集成,并希望使用具有全网域委托的服务用户来代表 Google Workspaces 中的用户请求数据。我的代码在AWS的EC2中运行。通读文档,最佳实践似乎是使用工作负载身份联合来作为服务用户进行身份验证,这样就不存在密钥泄露的风险。
我已按照Google 网站上的步骤设置与 AWS 的工作负载身份联合,此外,还在 google cloud shell 中运行以下命令:
gcloud iam service-accounts add-iam-policy-binding <service_account_email> \
--role=roles/iam.workloadIdentityUser \
--member="principalSet://iam.googleapis.com/projects/<project_id>/locations/global/workloadIdentityPools/<pool_id>/attribute.aws_role/arn:aws:sts::<aws_account_id>:assumed-role/<aws_role_name>" \
--project <google_cloud_project_name>
Run Code Online (Sandbox Code Playgroud)
我有以下测试应用程序代码:
const { google } = require("googleapis");
const { GoogleAuth } = require("google-auth-library");
const path = require("path");
module.exports = async (req, res) => {
const scopes = [
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/admin.directory.user.readonly",
];
let status = "";
try {
//Inject the client library config as the GOOGLE_APPLICATION_CREDENTIALS
const configPath = path.join(__dirname, "client_library_config.json");
process.env["GOOGLE_APPLICATION_CREDENTIALS"] = …Run Code Online (Sandbox Code Playgroud) amazon-web-services node.js google-cloud-platform gmail-api workload-identity
大约一周前,我在谷歌上设置了一个应用程序。现在,当我尝试运行时:
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
creds = None
if os.path.exists('token.pickle'):
with open(self.CREDENTIALS_PATH+self.conjoiner+'token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request()) ##error here
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Exception has occurred: RefreshError
('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?
python google-api google-oauth google-api-python-client gmail-api
gmail-api ×10
google-api ×5
gmail ×4
google-oauth ×3
java ×2
python ×2
gmail-addons ×1
go ×1
node.js ×1
php ×1
python-3.x ×1