问题描述
>>方法将标签应用于电子邮件,但是,我必须在我以编程方式应用的标签出现在gmail用户界面之前刷新页面。所需操作类似于如果手动选择Gmail邮件,然后从Gmail邮箱屏幕顶部的下拉标签应用程序应用标签:应用该标签异步。这是可能的编程方式吗?
代码
var applyLabel = function(gapiRequestURL,labelIdsArr)
{
$ .ajax({
url:gapiRequestURL,
method:POST,
contentType:application / json,
data:JSON.stringify({
addLabelIds:labelIdsArr
}),
success:function(msg){
// alert(JSON.stringify(msg));
},
error:function(msg){
alert(Error:+ JSON.stringify(msg));
var decisionWhichLabelToApply = function(messageContentsArr){
var testLabelOne =Label_12
var testLabelTwo =Label_13
var labelIdsArr = []
for(var i = 0; i< messageContentsArr.length; i ++){
var currentMessage = messageContentsArr [i]
var messageID = currentMessage.id
if(true){
var labelModifyURL =https://www.googleapis.com/gmail/v1/us ers / me / messages /+ messageID +/ modify?access_token =+ thisToken
labelIdsArr.push(testLabelOne)
applyLabel(labelModifyURL,labelIdsArr)
}
else {
var labelModifyURL =https://www.googleapis.com/gmail/v1/users/me/messages/+ messageID +/ modify?access_token =+ thisToken
labelIdsArr.push(testLabelTwo )
applyLabel(labelModifyURL,labelIdsArr)
}
}
}
不是我知道的。 Gmail网页界面做了一些惰性缓存,似乎没有注意到底层数据(即Inbox,IMAP,API等)的特别好的变化。我相信它不需要完整的浏览器(F5)刷新,但当然需要执行一些UI操作,例如点击标签或点击网页内刷新图标进行更新以显示。 p>
I'm using the Users.messages:modify method to apply labels to emails, however, I must refresh the page before the labels which I apply programmatically appear on the gmail user interface.
The desired action is akin to if I manually select a gmail message and then apply a label from the dropdown label applicator at the top of the gmail screen: the label is applied asynchronously. Is this possible to do programmatically?
Code
var applyLabel = function (gapiRequestURL, labelIdsArr)
{
$.ajax({
url: gapiRequestURL,
method: "POST",
contentType: "application/json",
data: JSON.stringify({
addLabelIds: labelIdsArr
}),
success: function(msg){
// alert(JSON.stringify(msg));
},
error: function(msg){
alert("Error:" + JSON.stringify(msg));
}
})
}
var decideWhichLabelToApply = function(messageContentsArr){
var testLabelOne = "Label_12"
var testLabelTwo = "Label_13"
var labelIdsArr = []
for(var i=0; i < messageContentsArr.length; i++){
var currentMessage = messageContentsArr[i]
var messageID = currentMessage.id
if (true){
var labelModifyURL = "https://www.googleapis.com/gmail/v1/users/me/messages/" + messageID + "/modify?access_token=" + thisToken
labelIdsArr.push(testLabelOne)
applyLabel(labelModifyURL, labelIdsArr)
}
else {
var labelModifyURL = "https://www.googleapis.com/gmail/v1/users/me/messages/" + messageID + "/modify?access_token=" + thisToken
labelIdsArr.push(testLabelTwo)
applyLabel(labelModifyURL, labelIdsArr)
}
}
}
Not that I know of. The Gmail web interface does some lazy caching and doesn't seem to notice particularly well changes to the underlying data (i.e. from Inbox, IMAP, API, etc). I believe it doesn't require a full browser (F5) refresh but certainly one needs to do some UI action like clicking on labels or hitting the in-webpage refresh icon for update to show up.
这篇关于Gmail API:异步标签更新/应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!