My Code: GoogleCredential credential
try {
// Authorize the request.
credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAccId)
.setServiceAccountPrivateKeyFromP12File(certFilePath)
.setServiceAccountScopes(Lists.newArrayList(YouTubeScopes.YOUTUBE))
.setServiceAccountUser(emailId)
.build();
credential.refreshToken()
Error Log:
Error |
Exception: 401 Unauthorized
Error |
com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
Error |
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
Error |
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
Error |
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
Error |
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)
Error |
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
Error |
at com.google.api.client.auth.oauth2.Credential$refreshToken.call(Unknown Source)
Error |
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
Error |
at viewlift.YouTubePublishService.authorizeCredentials(YouTubePublishService.groovy:82)
Error |
at viewlift.YouTubePublishService$$FastClassBySpringCGLIB$$48c3206b.invoke(<generated>)
Error |
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
Error |
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
Error |
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
Error |
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
Error |
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
Error |
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
Error |
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
Error |
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
Error |
at viewlift.YouTubePublishService$$EnhancerBySpringCGLIB$$6e11774.authorizeCredentials(<generated>)
Error |
at viewlift.YouTubePublishService$authorizeCredentials.call(Unknown Source)
Error |
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
Error |
at com.viewlift.ViewLiftUtilsService.createSocialAccount(ViewLiftUtilsService.groovy:128)
Error |
at com.viewlift.ViewLiftUtilsService$$FastClassBySpringCGLIB$$53f6d4a5.invoke(<generated>)
Error |
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
Error |
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
Error |
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
Error |
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
Error |
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
Error |
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
Error |
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
Error |
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
Steps i followed to create service account:
- I created a web application in oauth 2.0 in credentials
- Then i took the client id and with this i created a service account
- Now i am using this service account and p12 certificate generated from it to authenticate and create object of GoogleCredentials
- As soon as it goes for refresh token i given me 401 exception.
Any help would be appreciated in this case