Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Gmail API中邮箱的委托无效_Java_Gmail Api_Google Api Java Client_Google Email Settings Api - Fatal编程技术网

Java Gmail API中邮箱的委托无效

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, “错误”:[{ “域”:“全局”, “消息”:“无效委托”, “原

我正在尝试使用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;

    }

请在这方面帮助我,因为我仍在本地主机上运行此功能。

如果您想访问其他用户的电子邮件帐户,您必须启用允许代理代表其读取、发送和删除的邮件删除功能:

  • 登录到您的帐户

    注意:使用管理员帐户登录(不以 @gmail.com)

  • 从管理控制台主页,转到应用程序GsuiteGmail用户设置

  • 邮件委派旁边,选择让用户将对其邮箱的访问委派给域中的其他用户
  • (可选)选择包含要启用邮件委派的用户的每个组织,并选中邮件委派
  • 单击保存
  • 一旦启用,任何希望指派代表访问其电子邮件的用户必须在其Gmail帐户中。

    免责声明:我在Gmail和Gmail API平台上工作

    看起来您正在尝试获取帐户的所有代理的列表,因此必须使用而不是

    请注意,这将需要对代码进行进一步更改,以处理返回的代码

    另一方面,您正在收到
    “无效委托”
    错误,因为
    service.users().settings().delegates().get(user,“me”)
    正在提供
    me
    作为您尝试检索的委托的电子邮件。您需要提供一个有效的电子邮件地址,请求才能成功。然而,我意识到这很可能是由于您错误地使用了
    Get
    delegate方法而不是
    List
    delegates方法