2017-02-21 14 views
0

新しいラベルを作成するために公式Gmail PHPライブラリを使用しようとしています。私は標準のOauthを使用してユーザーを認証しています(必要な権限がすべて与えられています)。Gmail PHP APIフィルタの作成問題

しかし、私は次のエラーが表示されます

<b>Fatal error</b>: Uncaught exception 'Google_Service_Exception' with message '{ 
&quot;error&quot;: { 
    &quot;errors&quot;: [ 
    { 
    &quot;domain&quot;: &quot;global&quot;, 
    &quot;reason&quot;: &quot;invalidArgument&quot;, 
    &quot;message&quot;: &quot;Filter doesn't have any actions&quot; 
    } 
    ], 
    &quot;code&quot;: 400, 
    &quot;message&quot;: &quot;Filter doesn't have any actions&quot; 
} 
} 

次のようにコードは次のとおりです。設定されている

$gmail = new Google_Service_Gmail($google); 
$label = new Google_Service_Gmail_Label(); 
     $label->setId('Label_8'); 

     $label2 = new Google_Service_Gmail_Label(); 
     $label2->setId('UNREAD'); 

     $label3 = new Google_Service_Gmail_Label(); 
     $label3->setId('INBOX'); 

     $criteria = new Google_Service_Gmail_FilterCriteria(); 
     $criteria->setFrom('[email protected]'); 

     $action = new Google_Service_Gmail_FilterAction(); 
     $action->setAddLabelIds(array($label)); 
     $action->setRemoveLabelIds(array($label2,$label3)); 

     $filter = new Google_Service_Gmail_Filter(); 
     $filter->setCriteria($criteria); 
     $filter->setAction($action); 


     $result = $gmail->users_settings_filters->create('me',$filter); 

スコープ:

$google->setScopes(array('https://www.googleapis.com/auth/pubsub','https://mail.google.com','https://www.googleapis.com/auth/gmail.settings.basic')); 

すべてがプログラムで正常に見えます。私はコードをチェックして、アクションを割り当てています。私は、おそらくライブラリに何か問題があると信じています。どんな助言も役に立ちます。ログを分析することで問題が見つかり

+0

APIエクスプローラーでhttps://developers.google.com/gmail/api/v1/reference/users/settings/filters/create#try-itを実行すると、完全に機能します。 –

答えて

0

$action->setAddLabelIds(array($label)); 
    $action->setRemoveLabelIds(array($label2,$label3)); 

は次のようになります。現時点で

$action->setAddLabelIds(array('Label_8')); 
    $action->setRemoveLabelIds(array('UNREAD','INBOX')); 

一貫性のないAPI。

関連する問題