2017-12-29 70 views
0

내 코드에 문제가 있습니다. 너희들 나를 도울 수 있니?드라이브 빌더 오류 : API Google 드라이브 봄 부팅

내가 여기

과정 service = new com.google.api.services.drive.Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();에 오류 코드가 나의 코드입니다 : 내 모든 드라이브 목록을 표시 할

@Controller 
@RestController 
public class GoogleOauthController { 

    private static final String APPLICATION_NAME = "oauth drive"; 
    private static HttpTransport httpTransport; 
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); 
    private static com.google.api.services.drive.Drive service; 

    GoogleClientSecrets clientSecrets; 
    GoogleAuthorizationCodeFlow flow; 
    Credential credential; 

    @Value("${drive.client.clientId}") 
    private String clientId; 

    @Value("${drive.client.clientSecret}") 
    private String clientSecret; 

    @Value("${drive.client.redirectUri}") 
    private String redirectUri; 

    @RequestMapping(value = "/login/drive", method = RequestMethod.GET) 
    public RedirectView googleConnectionStatus(HttpServletRequest request) throws Exception { 
     return new RedirectView(authorize()); 
    } 

    @RequestMapping(value = "/login/callbackoauth", method = RequestMethod.GET, params = "code") 
    public List<File> oauth2Callback(@RequestParam(value = "code") String code) { 

     // System.out.println("code->" + code + " userId->" + userId + " 
     // query->" + query); 

     JSONObject json = new JSONObject(); 
     JSONArray arr = new JSONArray(); 

     List<File> result = new ArrayList<File>(); 

     // String message; 
     try { 
      TokenResponse response = flow.newTokenRequest(code).setRedirectUri(redirectUri).execute(); 
      credential = flow.createAndStoreCredential(response, "userID"); 

      service = new com.google.api.services.drive.Drive.Builder(httpTransport, JSON_FACTORY, credential) 
        .setApplicationName(APPLICATION_NAME).build(); 
      System.out.println(service); 
      Files.List request = service.files().list(); 

      do { 
        try { 
        FileList files = request.execute(); 

        result.addAll(files.getItems()); 
        request.setPageToken(files.getNextPageToken()); 
        } catch (IOException e) { 
        System.out.println("An error occurred: " + e); 
        request.setPageToken(null); 
        } 
       } while (request.getPageToken() != null && 
         request.getPageToken().length() > 0); 


     } catch (Exception e) { 

      System.out.println("exception cached "); 
      e.printStackTrace(); 
     } 

     return result; 
    } 

    private String authorize() throws Exception { 
     AuthorizationCodeRequestUrl authorizationUrl; 
     if (flow == null) { 
      Details web = new Details(); 
      web.setClientId(clientId); 
      web.setClientSecret(clientSecret); 
      clientSecrets = new GoogleClientSecrets().setWeb(web); 
      httpTransport = GoogleNetHttpTransport.newTrustedTransport(); 
      flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, 
        Collections.singleton(DriveScopes.DRIVE)).build(); 
     } 
     authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirectUri); 

     System.out.println("drive authorizationUrl ->" + authorizationUrl.build()); 
     return authorizationUrl.build(); 
    } 
} 

하지만 빌드 드라이브의 제약, 그리고이

There was an unexpected error (type=Internal Server Error, status=500). com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient.(Lcom/google/api/client/http/HttpTransport;Lcom/google/api/client/http/HttpRequestInitializer;Ljava/lang/String;Ljava/lang/String;Lcom/google/api/client/json/JsonObjectParser;Lcom/google/api/client/googleapis/services/GoogleClientRequestInitializer;Ljava/lang/String;Z)V

와 콘솔에서 오류 :

브라우저에서 오류입니다 당신이 Internal Server Errordocumentation에서 제안 된 조치를가 발생한 경우 7,731,

감사

답변

0

truncated exponential backoff를 사용하여 다시 시도하는 것입니다. 또한 멱등 원하지 않은 요청을 다시 시도하기 전에 검사를 포함하는 것이 좋습니다 (here).