我正在尝试向Google验证服务帐户,以便从服务器应用程序发送电子邮件。
这是由
完成的private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static HttpTransport HTTP_TRANSPORT;
private static final List<String> SCOPES =
Arrays.asList(GmailScopes.GMAIL_LABELS, GmailScopes.GMAIL_SEND);
return new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("xxxxxxxxxxxxxx.iam.gserviceaccount.com")
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(new File("C:/temp/google/secret.p12"))
.build();
我得到的服务器响应是
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Bad Request",
"reason" : "failedPrecondition"
} ],
"message" : "Bad Request"
}
在我的服务帐户中,我启用了“启用G Suite全域委派”选项
以上是尝试和验证的正确方法,还是我错过了一步