Gmail API returning status code 400, error “Mail s

2019-06-21 04:02发布

问题:

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?

回答1:

Your trial period could have expired. Check your status at admin.google.com