gpt4 book ai didi

java - OAuthProblem,缺少参数 access_token

转载 作者:行者123 更新时间:2023-11-30 06:30:45 26 4
gpt4 key购买 nike

我在尝试为用户获取访问 token 时遇到此错误。这与 facebook 应用程序的授权过程有关。产生该异常的代码如下:

OAuthClientRequest oAuthRequest = OAuthClientRequest
.tokenLocation("https://graph.facebook.com/oauth/access_token")
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId("myAppId")
.setClientSecret("myAppSecret")
.setRedirectURI("myAppURL").setCode(code)
.buildBodyMessage();

抛出的异常如下:

12:14:22,468 ERROR [STDERR] OAuthProblemException{description='Missing parameters:   
access_token', error='invalid_request', uri='null', state='null', scope='null'}
12:14:22,468 ERROR [STDERR]
at org.apache.amber.oauth2.common.exception.OAuthProblemException.error(OAuthProblemException.java:57)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.common.utils.OAuthUtils.handleOAuthProblemException(OAuthUtils.java:165)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.common.utils.OAuthUtils.handleMissingParameters(OAuthUtils.java:183)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.validator.OAuthClientValidator.validateRequiredParameters(OAuthClientValidator.java:90)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.validator.OAuthClientValidator.validateParameters(OAuthClientValidator.java:53)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.validator.OAuthClientValidator.validate(OAuthClientValidator.java:49)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.response.OAuthClientResponse.validate(OAuthClientResponse.java:61)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.response.OAuthClientResponse.init(OAuthClientResponse.java:56)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse.init(OAuthAccessTokenResponse.java:52)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.response.OAuthClientResponseFactory.createCustomResponse(OAuthClientResponseFactory.java:60)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:105)
12:14:22,468 ERROR [STDERR] at org.apache.amber.oauth2.client.OAuthClient.accessToken(OAuthClient.java:58)
12:14:22,469 ERROR [STDERR] at tpc.facebook.autenticacion.ServletOAuth2.obtenerCodeYAccessToken(ServletOAuth2.java:315)
12:14:22,469 ERROR [STDERR] at tpc.facebook.autenticacion.ServletOAuth2.doGet(ServletOAuth2.java:217)
12:14:22,469 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
12:14:22,469 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
12:14:22,469 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
12:14:22,469 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)1
12:14:22,469 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
12:14:22,469 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
12:14:22,469 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
12:14:22,469 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
12:14:22,469 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
12:14:22,469 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
12:14:22,469 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)

最佳答案

我在实现客户端和服务器时遇到了同样的问题,问题是 Apache Amber (Oltu) 项目中客户端示例中的一个错误:

首先你有授权码请求(有效):

OAuthClientRequest request = OAuthClientRequest
.authorizationLocation(AUTHORIZE_URL)
.setClientId(CLIENT_ID)
.setRedirectURI(REDIR_URL)
.setResponseType(CODE_RESPONSE)
.**buildQueryMessage**();

第二个关于访问 token 的请求(不起作用):

OAuthClientRequest request = OAuthClientRequest
.tokenLocation(ACCESS_TOKEN_URL)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setRedirectURI(REDIR_URL)
.setCode(code)
.**buildBodyMessage**();

错误与第二个请求中的 buildBodyMessage() 有关。通过 buildQueryMessage() 更改它。

享受 :)

关于java - OAuthProblem,缺少参数 access_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com