2017-02-21 7 views
0

Я пытаюсь использовать официальную библиотеку PHP Gmail для создания нового ярлыка. Я использую стандартный Oauth для аутентификации пользователя (все необходимые разрешения были предоставлены).Gmail PHP API Create Filter Issue

Но я получаю следующее сообщение об ошибке:

<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 на данный момент.