Gmail API返回状态代码400,错误“邮件服务未启用” [英] Gmail API returning status code 400, error "Mail service not enabled"
问题描述
我最近开始从gmail API看到以下错误:
{
code:400,
错误:[{
domain:global,
message:邮件服务未启用,
reason:failedPrecondition
$ b],
message:邮件服务未启用
}
我测试过的每个gmail API调用都会导致错误,但下面的代码显示了一个正常的示例:
public static列表与LT;字符串> getThreadIdsFromRFC822MessageIds(Collection< String> messageIds,User u)抛出IOException,NoOauthCredentialsException {
List< String> queryTerms = new ArrayList<>();
for(String messageId:messageIds){
queryTerms.add(rfc822msgid:+ messageId);
}
String queryString = Joiner.on(OR).join(queryTerms);
字符串fieldSelectionString =messages / threadId;
ListMessagesResponse messages = executeMessageQuery(u,queryString,fieldSelectionString);
列表< String> threadIds = new ArrayList<>(); (message.getMessages()!= null){
for(Message m:messages.getMessages()){
threadIds.add(m.getThreadId());
}
}
return threadIds;
}
private static ListMessagesResponse executeMessageQuery(User u,String queryString,String fieldSelectionString)throws IOException,NoOauthCredentialsException {
assert fieldSelectionString.length()> 0;
Gmail g = GmailAPIHelper.getGmailService(u);
Gmail.Users.Messages.List query = g.users()。messages()。list(me).setQ(queryString).setFields(fieldSelectionString);
ListMessagesResponse messages = executeAndLog(query,u);
返回消息;
}
其中,executeAndLog在Gmail.Users.Messages.List对象上调用.execute。
这个错误只影响到我的很小一部分用户,并且错误信息表明这是一个权限问题。我希望询问我的用户重新授权可以解决问题,但是我担心在出现权限问题时,我会收到此错误消息,而不是更常见的401。有没有人看过这个错误?
您的试用期可能已过期。请在admin.google.com上检查您的状态。I recently started seeing the following error from the gmail API:
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Mail service not enabled",
"reason" : "failedPrecondition"
} ],
"message" : "Mail service not enabled"
}
Every gmail api call I've tested causes the error, but the following code shows a normal example:
public static List<String> getThreadIdsFromRFC822MessageIds(Collection<String> messageIds, User u) throws IOException, NoOauthCredentialsException {
List<String> queryTerms = new ArrayList<>();
for (String messageId: messageIds) {
queryTerms.add("rfc822msgid:" + messageId);
}
String queryString = Joiner.on(" OR ").join(queryTerms);
String fieldSelectionString = "messages/threadId";
ListMessagesResponse messages = executeMessageQuery(u, queryString, fieldSelectionString);
List<String> threadIds = new ArrayList<>();
if (messages.getMessages() != null) {
for (Message m : messages.getMessages()) {
threadIds.add(m.getThreadId());
}
}
return threadIds;
}
private static ListMessagesResponse executeMessageQuery(User u, String queryString, String fieldSelectionString) throws IOException, NoOauthCredentialsException {
assert fieldSelectionString.length() > 0;
Gmail g = GmailAPIHelper.getGmailService(u);
Gmail.Users.Messages.List query = g.users().messages().list("me").setQ(queryString).setFields(fieldSelectionString);
ListMessagesResponse messages = executeAndLog(query, u);
return messages;
}
Where executeAndLog calls .execute on the Gmail.Users.Messages.List object.
This error is only affecting a very small number of my users, and the error message suggests that it is a problem with permissions. I expect that asking my users to reauthorize will fix the issue, but I am concerned that I'm getting this error message instead of the more usual 401 when there's a permission problem. Has anyone seen this error?
Your trial period could have expired. Check your status at admin.google.com
这篇关于Gmail API返回状态代码400,错误“邮件服务未启用”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!