Gmail PHP API创建过滤器问题



正在尝试使用官方的Gmail PHP库来创建一个新标签。我正在使用标准oauth来验证用户(已给出了所有必要的权限)。

但是我收到以下错误:

<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('test@gmail.com');
      $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'));

整理上一切看起来都很好。我什至检查了代码,它正在分配操作。我相信图书馆可能有问题。任何建议都会有所帮助。

通过分析日志来找到问题:

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

应该是:

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

目前不一致的API。

最新更新