2014-10-06 3 views
0

Gmail Java API에 약간 문제가 있습니다. 필자는 예제 코드를 재사용하여 쿼리에 맞는 모든 전자 메일을 제거하도록 수정했습니다. 쉽게 충분하지만 이메일은 삭제되지 않습니다. 어떤 아이디어?Gmail 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); 

    } 

} 

답변

1

삭제 작업은 .execute()해야합니다. :)

+0

축복, 고마워. 내가 뻔한 무엇인가 놓치고 있다는 것을 알았다! – NoTrueScotsman

관련 문제