使用Gmail API创建一个过滤器 [英] Create a filter using Gmail API

查看:113
本文介绍了使用Gmail API创建一个过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google最近发布了其新版Gmail API,现在可以创建过滤器

Google released recently a new version of its Gmail API which now makes possible to create filters.

然而,文档是相当有限的,我面临的问题,以使其工作。我正在使用他们的 PHP客户端的最新版本。任何帮助将不胜感激构建请求主体。

However the documentation is quite limited and I'm facing issues to get it working. I'm using the latest version of their PHP client. Any help would be appreciated to construct the request body.

public $gmail;
public function createFilter($userId) {

    try {

        $filter = new Google_Service_Gmail_Resource_UsersSettingsFilters();
        // Here, we should create the request body...
        // https://developers.google.com/gmail/api/v1/reference/users/settings/filters#resource
        // $filter->setCriteria() ??

        $this->gmail->users_settings_filters->create($userId, $filter);


    } catch (Exception $e) {
        // Logging errors...
    }

}

更新(工作方式)

UPDATE (Working method)

public $gmail;
public function createFilter($userId) {

    try {

       $filter = new Google_Service_Gmail_Filter([
            'criteria' => [
                'from' => 'example@gmail.com'
            ],
            'action' => [
                'addLabelIds' => ['STARRED']
            ]
        ]);

        $this->gmail->users_settings_filters->create($userId, $filter);


    } catch (Exception $e) {
        // Logging errors...
    }

}


推荐答案

请参阅 https://github.com/google/google-api-php-client#making-requests ,获取有关构建请求对象的指导。您应该能够使用本机PHP数组或自动生成的对象填充筛选器属性。示例:

See https://github.com/google/google-api-php-client#making-requests for guidance on constructing request objects. You should be able to populate the filter properties using native PHP arrays or the autogenerated objects. Example:

$filter = new Google_Service_Gmail_Resource_UsersSettingsFilters([
    'criteria' => [
        'from' => 'somebody@example.com'
    ],
    'action' => [
        'addLabelIds' => ['STARRED']
    ]
]);

这篇关于使用Gmail API创建一个过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆