【发布时间】:2017-03-16 19:46:41
【问题描述】:
我的代码: GoogleCredential 凭据
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 |
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)
我创建服务帐户的步骤:
- 我在 oauth 2.0 的凭据中创建了一个 Web 应用程序
- 然后我获取了客户端 ID,并以此创建了一个服务帐户
- 现在我正在使用此服务帐户和由此生成的 p12 证书来验证和创建 GoogleCredentials 对象
- 只要刷新令牌,我就给了我 401 异常。
在这种情况下,任何帮助将不胜感激
【问题讨论】:
标签: java google-api youtube-api google-api-java-client service-accounts