简体   繁体   English

Gmail API PHP - 从不同的账户读取 email

[英]Gmail API PHP - Reading an email from different accounts

Context:语境:

My gmail account is not a service account .我的 gmail 帐户不是服务帐户 I am writing a PHP CLI application which checks for an email from a specific sender and specific subject.我正在编写一个 PHP CLI 应用程序,它检查来自特定发件人和特定主题的 email。 Assume this application is for a custom domain but not part of GSuite.假设此应用程序用于自定义域,但不是 GSuite 的一部分。 I do not have server-wide control over our domain's emails.我对我们域的电子邮件没有服务器范围的控制。

I am using my own credentials.json file for Auth from Google APIs portal.我正在使用自己的credentials.json文件从 Google API 门户进行身份验证。 I modified the code from the Quickstart to fetch emails based on my query and get the specific email I need.我修改了快速入门中的代码,以根据我的查询获取电子邮件并获得我需要的特定 email。 (The user is 'me' by the way from Quickstart example). (顺便说一句,用户是“我”,来自快速入门示例)。

Reference: PHP documentation for Gmail API参考: PHP Gmail API的文档

Question:题:

How can I make this application work for any user within my domain?我怎样才能使这个应用程序适用于我域中的任何用户? Is there any possible way, I can do this without requiring another account with server-wide delegation(I hope the term is correct) access?有什么可能的方法,我可以做到这一点,而不需要另一个具有服务器范围委托(我希望这个词是正确的)访问权限的帐户?

For example例如

$tmp = new CustomClassUsingGmailAPI();
$emailIds = ["email1@customdomain", "email2@customdomain"];
foreach($emailIds as $emailId){
    $tmp->doTheRequiredTask($emailId);
}

The tutorial you are following uses Oauth2 to authorize your applications access to users data.您正在学习的教程使用 Oauth2 授权您的应用程序访问用户数据。

The user is 'me' by the way from Quickstart example).顺便提一下,用户是“我”,来自快速入门示例)。

Actually the user is always the person who logs in and authenticates the application.实际上,用户始终是登录和验证应用程序的人。 The only way to access private user data is to have the permission of the person who owns that data.访问私人用户数据的唯一方法是获得拥有该数据的人的许可。

There is no way to access the email of a non gsuite domain user.没有办法访问非gsuite域用户的email。 This is called data privacy and security.这称为数据隐私和安全。 You and your application can not access my data with out my permission.未经我的许可,您和您的应用程序无法访问我的数据。

Unless you convert your domain to a gsuite domain, you will not be able to access the users emails for that domain, without their permission.除非您将域转换为 gsuite 域,否则未经用户许可,您将无法访问该域的用户电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM