Java gmail API删除不起作用

Java gmail API删除不起作用,java,gmail,google-api-java-client,gmail-api,Java,Gmail,Google Api Java Client,Gmail Api,我在使用gmail Java API时遇到了一些问题。本质上,我只是重用了他们的示例代码,并对其进行了修改,以删除所有适合查询的电子邮件。很简单,但没有电子邮件被删除。有什么想法吗 public static void main (String [] args) throws IOException { HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new Jacks

我在使用gmail Java API时遇到了一些问题。本质上,我只是重用了他们的示例代码,并对其进行了修改,以删除所有适合查询的电子邮件。很简单,但没有电子邮件被删除。有什么想法吗

public static void main (String [] args) throws IOException {
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    clientSecrets = GoogleClientSecrets.load(jsonFactory,  new FileReader(CLIENT_SECRET_PATH));

    // Allow user to authorize via url.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            httpTransport, jsonFactory, clientSecrets, Arrays.asList(SCOPE))
    .setAccessType("online")
    .setApprovalPrompt("auto").build();

    String url = flow.newAuthorizationUrl().setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI)
            .build();
    System.out.println("Please open the following URL in your browser then type"
            + " the authorization code:\n" + url);

    // Read code entered by user.
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String code = br.readLine();

    // Generate Credential using retrieved code.
    GoogleTokenResponse response = flow.newTokenRequest(code)
            .setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential()
    .setFromTokenResponse(response);

    // Create a new authorized Gmail API client
    Gmail service = new Gmail.Builder(httpTransport, jsonFactory, credential)
    .setApplicationName(APP_NAME).build();

    // Retrieve a page of Threads; max of 100 by default.
    ListThreadsResponse threadsResponse = service.users().threads().list(USER).setQ("category:Promotions").execute();
    List<Thread> threads = threadsResponse.getThreads();

    // Delete each Thread.
    for (Thread thread : threads) {
              String ThreadID = thread.getId();
              service.users().threads().delete(USER, ThreadID);

    }

}
publicstaticvoidmain(字符串[]args)引发IOException{
HttpTransport HttpTransport=新的NetHttpTransport();
JsonFactory JsonFactory=新的JacksonFactory();
clientSecrets=GoogleClientSecrets.load(jsonFactory,新文件读取器(CLIENT_SECRET_PATH));
//允许用户通过url进行授权。
GoogleAuthorizationCodeFlow=新建GoogleAuthorizationCodeFlow.Builder(
httpTransport、jsonFactory、clientSecrets、Arrays.asList(范围))
.setAccessType(“在线”)
.setApprovalPrompt(“自动”).build();
字符串url=flow.newAuthorizationUrl().setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI)
.build();
System.out.println(“请在浏览器中打开以下URL,然后键入”
+“授权代码:\n”+url);
//读取用户输入的代码。
BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in));
字符串代码=br.readLine();
//使用检索到的代码生成凭据。
GoogleTokenResponse=flow.newTokenRequest(代码)
.setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI).execute();
GoogleCredential凭证=新的GoogleCredential()
.setFromTokenResponse(响应);
//创建新的授权Gmail API客户端
Gmail服务=新的Gmail.Builder(httpTransport、jsonFactory、凭证)
.setApplicationName(APP_NAME).build();
//检索一页线程;默认情况下最大值为100。
ListThreadsResponse threadsResponse=service.users().threads().list(USER.setQ)(“类别:促销”).execute();
List threads=threadsResponse.getThreads();
//删除每个线程。
用于(线程:线程){
String ThreadID=thread.getId();
service.users().threads().delete(用户,线程ID);
}
}

您必须执行删除操作的.execute()

您必须执行删除操作的.execute()

您必须执行删除操作的.execute()

您必须执行删除操作的.execute()

您尝试过REST客户端了吗?它运行得很好。 例子: 如果您想删除一条消息,您可以尝试通过REST来跟踪端点。


您将收到204的响应,您的邮件将被删除。

您是否尝试过REST客户端。它运行良好。 例子: 如果您想删除一条消息,您可以尝试通过REST来跟踪端点。


您将收到204的响应,您的邮件将被删除。

您是否尝试过REST客户端。它运行良好。 例子: 如果您想删除一条消息,您可以尝试通过REST来跟踪端点。


您将收到204的响应,您的邮件将被删除。

您是否尝试过REST客户端。它运行良好。 例子: 如果您想删除一条消息,您可以尝试通过REST来跟踪端点。


您将收到回复204,您的邮件将被删除。

祝福您,谢谢。我知道我错过了一些明显的东西!祝福你,谢谢你。我知道我错过了一些明显的东西!祝福你,谢谢你。我知道我错过了一些明显的东西!祝福你,谢谢你。我知道我错过了一些明显的东西!