Create a gmail filter with Gmail API nodejs, Error: Filter doesn't have any criteria

后端 未结 1 534
旧时难觅i
旧时难觅i 2020-12-07 04:27

Im having trouble creating a filter with Gmail API using node. Auth and scopes are fine; I get err \"Filter doesn\'t have any criteria\". Im guessing that im doing something

相关标签:
1条回答
  • 2020-12-07 04:54

    How about this modification?

    function createFilter(auth){
      var gmail = google.gmail('v1');
      var data = {
        "criteria": {
          "from": "someone@gmail.com",
        },
        "action": {
          "removeLabelIds": [
            "INBOX",
          ],
        },
      };
      gmail.users.settings.filters.create({
        auth: auth,
        userId: 'me',
        resource: data,
      }, function(err, result) {
        if (err) {
          console.log( err);
        } else {
          console.log( result );
          callback( result );
        }
      });
    }
    

    Note :

    • If the error of Insufficient Permission occurs, please add https://www.googleapis.com/auth/gmail.settings.basic to the scopes. When the scopes is modified, please remove the file including refresh token and then reauthorize it. By this, new scopes are reflected to the refresh token.

    If this didn't work, I'm sorry.

    Edit :

    I confirmed that when I used v27.0.0, v26.0.1 and v25.0.0 for googleapis, the error of Filter doesn\'t have any criteria' occurs. So can you downgrade the version to v24.0.0? When I use v24.0.0, it works fine. It is reported that there are some bugs for the recent updated googleapis for node.js. So I'm using v24.0.0.

    0 讨论(0)
提交回复
热议问题