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