【问题标题】:Can i get the mail of a message sender or receiver using Gmail API in PHP?我可以在 PHP 中使用 Gmail API 获取消息发送者或接收者的邮件吗?
【发布时间】:2020-05-16 08:11:22
【问题描述】:

我正在尝试构建一个网络邮件来帮助我的团队更快地检查他们的邮件。但不知何故,当我要求完整的原始消息或标题时,我没有得到完整的响应,它会切断 之间的文本。

API Explorer 返回(响应减少到有趣的内容):

"\"Google Download Your Data\" \u003cnoreply@google.com\u003e"

(\u003c 是

当我得到(响应减少到有趣的事情)时:

"Google Download Your Data"

代码:

<?php
require dirname(__DIR__) . '/vendor/autoload.php';

$client = new Google_Client();
$client->setScopes(Google_Service_Gmail::MAIL_GOOGLE_COM);
$client->setAuthConfig(PATH_TO_CRED);
$client->setSubject(MAIL);

$service = new Google_Service_Gmail($client);
$messages = $service->users_messages->listUsersMessages('me');
foreach ($messages as $message) {
    $mail = $service->users_messages->get('me', $message->getId());
    foreach ($mail->getPayload()->getHeaders() as $header) {
        if ($header->getName() == 'From') {
            echo $header->getValue();
            continue;
        }
    }
}

【问题讨论】:

  • 我使用 toolbox.googleapps.com/apps/encode_decode 解码 RAW 消息并收到邮件,但无法使用 PHP 获得相同的响应。
  • 说起来最简单,我的老板想要一个工具来更快地处理邮件并拥有一个共享工具,而不是使用获取关键信息的同一个 gmail 帐户

标签: php json api gmail


【解决方案1】:

只需要声明头文件application/json即可。

<?php
header('Content-Type: application/json');

【讨论】:

    猜你喜欢
    • 2014-10-12
    • 2018-07-14
    • 2015-07-28
    • 1970-01-01
    • 2019-10-01
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多