【问题标题】:Gmail PHP API Create Filter IssueGmail PHP API 创建过滤器问题
【发布时间】:2017-02-21 17:26:42
【问题描述】:

我正在尝试使用官方 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'));

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

【问题讨论】:

标签: php gmail gmail-api


【解决方案1】:

通过分析日志发现问题:

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

应该是:

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

目前 API 不一致。

【讨论】:

    猜你喜欢
    • 2016-07-22
    • 2016-12-22
    • 2018-08-17
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    相关资源
    最近更新 更多