Niedawno rozpoczął widząc następujący błąd z API Gmail:Gmail API powrocie kod statusu 400, błąd „usługa poczty nie włączone”
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Mail service not enabled",
"reason" : "failedPrecondition"
} ],
"message" : "Mail service not enabled"
}
Każde wywołanie gmail api Przetestowałem powoduje błąd, ale Poniższy kod pokazuje normalne przykład:
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;
}
Gdzie executeAndLog wywołuje .Execute na obiekcie Gmail.Users.Messages.List.
Ten błąd dotyczy tylko bardzo małej liczby moich użytkowników, a komunikat o błędzie sugeruje, że jest to problem z uprawnieniami. Oczekuję, że poproszenie moich użytkowników o ponowną autoryzację naprawi ten problem, ale obawiam się, że otrzymuję ten komunikat o błędzie zamiast bardziej typowego 401, gdy wystąpił problem z pozwoleniem. Czy ktoś widział ten błąd?
Przejdź na https://console.developers.google.com i włącz interfejs API Gmaila. – Nabin
To jest całkiem nowe; powinien odpowiadać znacznikowi isMailboxSetup dla konta w interfejsie Directory API: https://developers.google.com/admin-sdk/directory/v1/reference/users#isMailboxSetup. Jeśli jest to fałsz, interfejs API Gmaila nie może być użyty dla konta. –