I am developing one spring boot application where I have to upload files to the google drive.
I have tried to authenticate using GoogleOAuth2Template. Below is code snippet
GoogleOAuth2Template template = new GoogleOAuth2Template(clientId,
clientSecret);
AccessGrant accessGrant =template.authenticateClient();
But when calling authenticateClient()
I am getting 404 error
.
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.social.google.connect.GoogleOAuth2Template.postForAccessGrant(GoogleOAuth2Template.java:48) ~[spring-social-google-1.0.0.RELEASE.jar:1.0.0.RELEASE]
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:194) ~[spring-social-core-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at com.cookwala.controller.GoogleDriveController.connectToAPi(GoogleDriveController.java:26) ~[classes/:?]
at com.cookwala.controller.GoogleDriveController$$FastClassBySpringCGLIB$$ffe75835.invoke(<generated>) ~[classes/:?]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721) ~[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:97) ~[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]
Also tired calling overloaded method authenticateClient(String scope) , still getting same error.
I am doing above code to get the instance of org.springframework.social.google.api.Google
so that can create directory and upload file to Google Drive.
Am I missing something here or is there any other way to get access token from google to connect to google api.