【发布时间】:2017-02-21 17:26:42
【问题描述】:
我正在尝试使用官方 Gmail PHP 库来创建新标签。我正在使用标准 Oauth 对用户进行身份验证(已授予所有必要的权限)。
但我收到以下错误:
<b>Fatal error</b>: Uncaught exception 'Google_Service_Exception' with message '{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Filter doesn't have any actions"
}
],
"code": 400,
"message": "Filter doesn't have any actions"
}
}
代码如下:
$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'));
以编程方式看起来一切都很好。我什至检查了代码,它正在分配操作。我相信图书馆可能有问题。任何建议都会有所帮助。
【问题讨论】:
-
如果我在 developers.google.com/gmail/api/v1/reference/users/settings/… 使用他们的 API 浏览器执行相同操作,它会完美运行。