1
Google最近发布了其新版Gmail API,现在可以使用create filters。使用Gmail API创建过滤器
但是,文档是相当有限的,我面临的问题,以使其工作。我正在使用PHP client的最新版本。任何帮助将不胜感激构建请求主体。
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(加工方法)
public $gmail;
public function createFilter($userId) {
try {
$filter = new Google_Service_Gmail_Filter([
'criteria' => [
'from' => '[email protected]'
],
'action' => [
'addLabelIds' => ['STARRED']
]
]);
$this->gmail->users_settings_filters->create($userId, $filter);
} catch (Exception $e) {
// Logging errors...
}
}
非常感谢@Brandon。我用一个工作解决方案更新了我的问题。 – flo