2016-08-15 20 views
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... 
    } 

} 

答えて

1

は、リクエストオブジェクトを構築する上での指針のためhttps://github.com/google/google-api-php-client#making-requestsを参照してください。ネイティブのPHP配列または自動生成されたオブジェクトを使用して、フィルタのプロパティを設定できるはずです。例:

$filter = new Google_Service_Gmail_Resource_UsersSettingsFilters([ 
    'criteria' => [ 
     'from' => '[email protected]' 
    ], 
    'action' => [ 
     'addLabelIds' => ['STARRED'] 
    ] 
]); 
+0

ありがとう@Brandon。私は実際の解決策で私の質問を更新しました。 – flo

関連する問題