Java Gmail API中邮箱的委托无效
我正在尝试使用Gmail API获取邮箱的代理。 我的应用程序运行在Google App engine上,具有使用电子邮件设置API添加、删除和获取代理的功能。 现在我计划将这些功能迁移到Gmail API,因为电子邮件设置API将被弃用 就技术而言,我正在使用Java语言。 我遵循了Gmail API提供的所有步骤。Gmail API的身份验证成功。但当我试图获得代理时,它给出了以下错误- 404找不到 { “代码”:404, “错误”:[{ “域”:“全局”, “消息”:“无效委托”, “原因”:“未找到” } ], “消息”:“无效委托” } 下面是控制台内部的错误-Java Gmail API中邮箱的委托无效,java,gmail-api,google-api-java-client,google-email-settings-api,Java,Gmail Api,Google Api Java Client,Google Email Settings Api,我正在尝试使用Gmail API获取邮箱的代理。 我的应用程序运行在Google App engine上,具有使用电子邮件设置API添加、删除和获取代理的功能。 现在我计划将这些功能迁移到Gmail API,因为电子邮件设置API将被弃用 就技术而言,我正在使用Java语言。 我遵循了Gmail API提供的所有步骤。Gmail API的身份验证成功。但当我试图获得代理时,它给出了以下错误- 404找不到 { “代码”:404, “错误”:[{ “域”:“全局”, “消息”:“无效委托”, “原
public Delegate retrieveEmailDelegates(String user, Gmail service) throws Exception {
if (isBlankOrNullString(user)) {
throw new IllegalArgumentException();
}
Delegate delegatesResponse=null;
try {
System.out.println("Call retrieveEmailDelegates for "+user);
delegatesResponse = service.users().settings().delegates().get(user, "me").execute();
System.out.println("-------service" + delegatesResponse.getDelegateEmail());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return delegatesResponse;
}
*com.google.api.client.googleapis.json.GoogleJsonResponseException:未找到404
{
“代码”:404,
“错误”:[{
“域”:“全局”,
“消息”:“无效委托”,
“原因”:“未找到”
} ],
“消息”:“无效委托”
}
在
com.google.api.client.googleapis.json.GoogleJsonResponseException.fro
m(GoogleJsonResponseException.java:150)
在com.google.api.client.googleapis.services.json.AbstractGoogleJsonClie
ntRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
在com.google.api.client.googleapis.services.json.AbstractGoogleJsonClie
ntRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
在com.google.api.client.googleapis.services.AbstractGoogleClientRequest上
$1.interceptResponse(AbstractGoogleClientRequest.java:321)
位于com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1067)
在com.google.api.client.googleapis.services.AbstractGoogleClientRequest上
.executeUnparsed(AbstractGoogleClientRequest.java:419)
在com.google.api.client.googleapis.services.AbstractGoogleClientRequest上
.executeUnparsed(AbstractGoogleClientRequest.java:352)
在com.google.api.client.googleapis.services.AbstractGoogleClientRequest上
.execute(AbstractGoogleClientRequest.java:469)
在com.aeegle.services.GmailService.retrieveEmailDelegates(GmailService。
java:106)
在com.aeegle.DAOImpl.EmailDAOImpl.getDelegatesMail(EmailDAOImpl.java:1
43)
在controllers.DelegateController.getListDelegatesMail(DelegateControll
er.java:82)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl。
爪哇:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(delegatingmethodaccess
sorImpl.java:43)
位于java.lang.reflect.Method.invoke(Method.java:498)
atplay.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:557)
atplay.mvc.ActionInvoker.invoke(ActionInvoker.java:508)
atplay.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
atplay.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
atplay.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
在play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:255)
Invoker$Invocation.run(Invoker.java:278)
在play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:233)
位于java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:51
1)
在java.util.concurrent.FutureTask.run(FutureTask.java:266)处
位于java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask。
访问$201(ScheduledThreadPoolExecutor.java:180)
位于java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask。
运行(ScheduledThreadPoolExecutor.java:293)
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor。
爪哇:1149)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:624)
运行(Thread.java:748)*
您可以观察到Gmail服务热线106有问题。现在我要发布我的java代码
1:-身份验证代码-
public Gmail getGmailService(String email) throws Exception {
System.out.println("-------------getGmailService");
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
Collection<String> SCOPES = new ArrayList<String>();
SCOPES.add(GmailScopes.GMAIL_SETTINGS_BASIC);
SCOPES.add(GmailScopes.MAIL_GOOGLE_COM);
SCOPES.add(GmailScopes.GMAIL_MODIFY);
SCOPES.add(GmailScopes.GMAIL_READONLY);
GoogleCredential credential;
// To load classpath resources.
ClassLoader classLoader = getClass().getClassLoader();
new File(SERVICE_ACCOUNT_PKCS12_FILE_PATH);
credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL).setServiceAccountUser(email).setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(new File(SERVICE_ACCOUNT_PKCS12_FILE_PATH)).build();
System.out.println("----calling Builder");
service = new Gmail.Builder(httpTransport, jsonFactory, null).setHttpRequestInitializer(credential)
.setApplicationName(APPLICATION_NAME).build();
return service;
}
请在这方面帮助我,因为我仍在本地主机上运行此功能。如果您想访问其他用户的电子邮件帐户,您必须启用允许代理代表其读取、发送和删除的邮件删除功能:
“无效委托”
错误,因为service.users().settings().delegates().get(user,“me”)
正在提供me
作为您尝试检索的委托的电子邮件。您需要提供一个有效的电子邮件地址,请求才能成功。然而,我意识到这很可能是由于您错误地使用了Get
delegate方法而不是List
delegates方法