使用Gmail API nodejs创建Gmail过滤器,错误:过滤器没有任何标准 [英] Create a gmail filter with Gmail API nodejs, Error: Filter doesn't have any criteria
问题描述
我无法用Gmail API使用节点创建过滤器。认证和范围很好;我得到错误过滤器没有任何标准。我猜,即时通讯做错了头/身体/资源参数,但无法解决它。
继承人的功能,我已经尝试了一些变种:
函数createFilter(auth){
var gmail = google.gmail({version:'v1','auth' :AUTH});
//创建过滤规则
var data = {
resource:{
criteria:{
from:someone@gmail.com
},
action:{
removeLabelIds:[INBOX]
}
},
userId:'me'
}
//发送规则到Gmail
gmail.users.settings.filters.create(data,function(err,result){
if(err){
console.log(err);
} else {
console.log(result);
callback(result);
}
});
};
文档:
创建过滤器 https://developers.google.com/gmail/api/ v1 / reference / users / settings / filters / create
过滤资源 https://developers.google.com/gmail/api/v1/reference/users/settings/filters#resource
申请
https://github.com/google/google-api-nodejs -client /#making-authenticated-requests
php中的类似工作请求:
< a href =https://stackoverflow.com/questions/38961008/create-a-filter-using-gmail-api>使用Gmail API创建过滤器
任何帮助都会被赞赏!
function createFilter(auth){
var gmail = google.gmail('v1');
var data = {
criteria:{$ b $from:someone@gmail.com,
},
action:{
removeLabelIds:[
INBOX,
],
},
};
gmail.users.settings.filters.create({
auth:auth,
userId:'me',
resource:data,
},function(err ,结果){
if(err){
console.log(err);
} else {
console.log(result);
callback(result) ;
}
});
}
注意:
- 如果发生错误
权限不足
,请添加https://www.googleapis.com/auth/gmail .settings.basic
到作用域。当范围被修改时,请删除包含刷新令牌的文件,然后重新授权它。这样,新的作用域就会反映到刷新标记中。
如果这不起作用,我很抱歉。
>编辑:
我确认当我使用v27.0.0,v26.0.1和v25.0.0 for googleapis时, 的错误过滤器没有任何标准'
发生。那么你可以将版本降级到v24.0.0吗?当我使用v24.0.0时,它工作正常。据报道,最近为node.js更新的googleapis存在一些错误。所以我使用v24.0.0。
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 wrong with headers / body / Resource Parameter, but cant work it out.
Heres the function, I've tried a number of variants:
function createFilter(auth){
var gmail = google.gmail({version:'v1','auth':auth});
// Create filter rule
var data = {
resource: {
criteria: {
from: "someone@gmail.com"
},
action: {
removeLabelIds: ["INBOX"]
}
},
userId: 'me'
}
// Send rule to Gmail
gmail.users.settings.filters.create(data, function (err, result) {
if (err) {
console.log( err);
} else {
console.log( result );
callback( result );
}
});
};
docs:
Create Filter https://developers.google.com/gmail/api/v1/reference/users/settings/filters/create Filter Resource https://developers.google.com/gmail/api/v1/reference/users/settings/filters#resource Making Requests https://github.com/google/google-api-nodejs-client/#making-authenticated-requests
similar working req in php:
Create a filter using Gmail API
Any help would be so much appreciated!
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 addhttps://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.
这篇关于使用Gmail API nodejs创建Gmail过滤器,错误:过滤器没有任何标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!